JS:
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
页脚注意:此JSON是使用PHP函数json_encode生成的。
Chrome控制台错误:位置41的JSON中出现意外数字
$。parseJSON无法正常工作可以请帮助我为什么不能正常工作?
答案 0 :(得分:-1)
您应该只使用double quoted strings
var data = [{"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":"€ (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":"€ (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":"€ (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"}];
var stringified = JSON.stringify(data);
console.log(stringified);
// this is a valid JSON String, now you can JSON.parse(stringified)