I know it's dummy question but I spent hours in this and cant find the cause. I have JSON array file and trying to fetch the array in jQuery but parse error appears. Here is my code:
var obj=[
{
id : 1,
name : 'name1',
age : 67,
feedback : 'feedback1'
},
{
id : 2,
name : "name2',
age : 30,
feedback : 'feedback2'
},
{
id : 3,
name : 'name3',
age : 59,
feedback : 'feedback3'
},
{
id : 4,
name : 'name4',
age : 17,
feedback : 'feedback4'
},
]
in JS:
$(document).ready(function(){
$.ajax({
url : 'data.json',
error : function(that,e) {
console.log(e);
},
success : function(data) {
alert(JSON.parse(data.obj[0].name));
}
});
});
Your data.json should be valid json.
[{
"id": 1,
"name": "name1",
"age": 67,
"feedback": "feedback1"
}, {
"id": 2,
"name": "name2",
"age": 30,
"feedback": "feedback2"
}, {
"id": 3,
"name": "name3",
"age": 59,
"feedback": "feedback3"
}, {
"id": 4,
"name": "name4",
"age": 17,
"feedback": "feedback4"
}]
You can check the validity of you json file here - http://jsonlint.com/
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.