0

I'm loading a local file that contains a JSON object which has been validated by both jsonlint and freeformater and I'm getting a not well-formed error in Firefox's console.

I looked at this question and tried to use that but it doesn't seem to work.

This is the text in the file:

    {
    "CallsStats": [
        {
            "name": "Sales",
            "CallsWaiting": "1",
            "OnInboundACDCalls": "0",
            "LongestWaitTime": "00:01:14",
            "LongestOnHoldTime": "N/A",
            "Queue_Interval": {
                "name": "CurrentShift",
                "CallsAbandoned": "1",
                "CallsEntered": "18",
                "CallsAnswered": "16",
                "AverageWaitTime": "00:01:09",
                "AverageHoldTime": "00:00:29",
                "AverageTalkTime": "00:03:42"
            }
        },
        {
            "name": "Marketing",
            "CallsWaiting": "0",
            "OnInboundACDCalls": "0",
            "LongestWaitTime": "N/A",
            "LongestOnHoldTime": "N/A",
            "Queue_Interval": {
                "name": "CurrentShift",
                "CallsAbandoned": "0",
                "CallsEntered": "0",
                "CallsAnswered": "0",
                "AverageWaitTime": "N/A",
                "AverageHoldTime": "N/A",
                "AverageTalkTime": "N/A"
            }
        },
        {
            "name": "Support",
            "CallsWaiting": "14",
            "OnInboundACDCalls": "14",
            "LongestWaitTime": "00:04:42",
            "LongestOnHoldTime": "00:02:48",
            "Queue_Interval": {
                "name": "CurrentShift",
                "CallsAbandoned": "816",
                "CallsEntered": "2696",
                "CallsAnswered": "1349",
                "AverageWaitTime": "00:03:36",
                "AverageHoldTime": "00:00:13",
                "AverageTalkTime": "00:03:27"
            }
        }
    ]
}

And this is my code:

function loadJson() {
    $(document).ready(function()
        {
            $.ajax(
                {
                    url: 'sampledata.json', 
                    dataType: 'application/json',
                    success:function(data) {
                            console.log(data);
                    }
                }
            );
        });
}

I don't know if it helps, but this is what the console shows: enter image description here

I tried before with $.getJSON and was getting the same result.

EDITS TO THE QUESTION

I tried what James Montagne suggested in the comments (I thought that was the what $.getJSON would do automatically... And this is what I got: enter image description here

So I realized that some invisible characters were a problem and I got rid of them.

Now I'm able to load the file as text and convert it to a JSON object using JSON.parse(data) but still, it shows an error: enter image description here

What could it be, and should I be concerned?

Community
  • 1
  • 1
dzmr83
  • 63
  • 8
  • 1
    Try changing the dataType to "text" and see what you are actually getting back as a response. Perhaps it's not what you think it is (server side error message, etc.) – James Montagne Dec 25 '15 at 02:21
  • @JamesMontagne Great, that helped!!! See my edits, though. – dzmr83 Dec 25 '15 at 14:51
  • contentType: "application/json; charset=utf-8", dataType: "json", – Hasta Tamang Dec 25 '15 at 16:51
  • @HastaPasta - still getting the same syntax error. But it got solved after specifying the mime type as per [this article](http://stackoverflow.com/questions/18291390/jquery-getjson-syntax-error-on-a-valid-json) – dzmr83 Dec 27 '15 at 03:25
  • @JamesMontagne - do you want to a submit an answer? – dzmr83 Dec 28 '15 at 02:58

0 Answers0