var response = '[{
"userid":"14",
"mobile":"a:1:{i:0;s:10:\"9925847424\";}",
"pet_type":"Found",
"pet_cat":"2",
"petbreed":"1",
"pet_long":"72.58522",
"pet_lat":"23.087618",
"pet_reward":"",
"currency":"\u20ac (EUR)",
"name":"",
"date":"2017-03-27",
"pet_city":"Los Angelese",
"pid":"200",
"lid":"194",
"type":"Found",
"pet_lost_location":"Santa Monica",
"pet_lost_address":" dshtjh",
"pet_postal":"380009",
"pet_country":"United states",
"distance":"0.15473920640658162",
"dogbreed":null,
"catbreed":"Abyssinian cat",
"img":"a:1:{i:0;s:9:\"img1.jpeg\";}",
"pet_hidenum":"249310649"
},
{
"userid":"13",
"mobile":null,
"pet_type":"Lost",
"pet_cat":"1",
"petbreed":"5",
"pet_long":"72.58522",
"pet_lat":"23.087618",
"pet_reward":"23",
"currency":"\u20ac (EUR)",
"name":"pappy",
"date":"2017-04-27",
"pet_city":"ahmedavad",
"pid":"233",
"lid":"227",
"type":"Lost",
"pet_lost_location":"sivranjani",
"pet_lost_address":"ahmedavad",
"pet_postal":" dmart",
"pet_country":"India",
"distance":"0.15473920640658162",
"dogbreed":"Aidi",
"catbreed":null,
"img":"a:4:{i:0;s:9:\"img1.jpeg\";i:1;s:9:\"img2.jpeg\";i:2;s:8:\"img3.png\";i:3;s:9:\"img4.jpeg\";}",
"pet_hidenum":"730117427"
},
{
"userid":"13",
"mobile":null,
"pet_type":"Found",
"pet_cat":"2",
"petbreed":"7",
"pet_long":"72.58522",
"pet_lat":"23.087618",
"pet_reward":"",
"currency":"\u20ac (EUR)",
"name":"",
"date":"2017-04-27",
"pet_city":"a",
"pid":"234",
"lid":"228",
"type":"Found",
"pet_lost_location":"asds",
"pet_lost_address":"asdsffas",
"pet_postal":"qwer",
"pet_country":"India",
"distance":"0.15473920640658162",
"dogbreed":null,
"catbreed":"Asian cat",
"img":"a:4:{i:0;s:9:\"img1.jpeg\";i:1;s:8:\"img2.png\";i:2;s:9:\"img3.jpeg\";i:3;s:8:\"img4.png\";}",
"pet_hidenum":"358512553"
},
{
"userid":"16",
"mobile":"",
"pet_type":"Lost",
"pet_cat":"2",
"petbreed":"511",
"pet_long":"72.58522",
"pet_lat":"23.087618",
"pet_reward":"1",
"currency":"$ (USD)",
"name":"Cade1",
"date":"1970-01-01",
"pet_city":"Ahmedabad",
"pid":"236",
"lid":"230",
"type":"Lost",
"pet_lost_location":"California",
"pet_lost_address":"12 San Diego",
"pet_postal":"380008",
"pet_country":"United states",
"distance":"0.15473920640658162",
"dogbreed":null,
"catbreed":"Unknown",
"img":"a:1:{i:0;s:9:\"img1.jpeg\";}",
"pet_hidenum":"501387450"
}]';
res = $.parseJSON(response);
JSBIN链接:https://jsbin.com/rarizavocu/edit?js,output
页脚注:通过使用PHP函数json_encode生成此JSON。
Chrome的控制台错误:在位置意外的数量JSON 41
$ .parseJSON工作不任何人可以请帮助我,为什么它不工作?
使用JSON.parse(响应); –
它似乎是一个多行字符串,多行字符串只允许通过字符串模板字面值https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals。 JSOn允许**双引号**,并使用单引号。 – Hitmands
你有没有尝试删除JS中的开始和结束报价而不是使用JSON.parse等?就像'var data = response.replace(/(^')|('$)/ g,'');'。不知道,但你可以尝试一次。 –