简体   繁体   中英

Not well formed error while accessing JSON with jquery

So I have a JSON file whose contents I wish to access and store in an array. Everything seems to be working fine but I am getting an error in Firefox console.

Not Well Formed.

and it is pointing to my JSON. I validated my JSON at JSONLint and it says "Valid JSON".

My jquery is:

$(function(){


$('#test').click(function(event){

$.getJSON("myfile.json",function(data){

var items=[];

$.each(data, function(key, val){

items.push(key + "," + val[0].subject + "," + val[0].room);

});
alert('transfer successful');
console.log(items);

});

});

});

My JSON looks something like this:

{
"8": [ {"subject":"Signals","room":"L20"} ],
"9": [ {"subject":"something","room":"L20"} ]
}

It may here be noted that this code is working fine with the items array getting populated as expected. But I cannot understand why I am getting the Not well formed error.

This happens in FireFox when Content-Type is not set. Ensure you are returning the correct mimetype for your myfile.json request ("application/json" etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM