-5
嗨我想解析簡單的JSON(字符串),但我得到錯誤。 這是目標,我需要得到JOSN.parse函數無法正常工作
{
"heading" : "The movies",
"box5" : "Click on icon to add text.",
"box1" : "At the movies,you can watch for an hour. ",
"box2" : "You can go eat popcorn,candy,and soda. ",
"box7" : "At the movies you will want to go again. ",
"box3" : "At the movies ,you can play games.",
"box4" : "you can go and have fun with your friends and family.And get to spent time with them.======== ",
"box6" : "Click on icon to add text."
};
。========
我覺得這是有規律的字符串中的字符
當我刪除=== =====我造成
var st = '{"heading": "The movies","box5": "Click on icon to add text.","box1": "At the movies,you can watch for an hour. ","box2": "You can go eat popcorn,candy,and soda. ","box7": "At the movies you will want to go again. ","box3": "At the movies ,you can play games.","box4": "you can go and have fun with your friends and family.And get to spent time with them.","box6": "Click on icon to add text."}';
console.log(st);
var res = JSON.parse(st);
console.log('res: ' + res.heading);
包括
var st = '{"heading": "The movies","box5": "Click on icon to add text.","box1": "At the movies,you can watch for an hour. ","box2": "You can go eat popcorn,candy,and soda. ","box7": "At the movies you will want to go again. ","box3": "At the movies ,you can play games.","box4": "you can go and have fun with your friends and family.And get to spent time with them.======== \t ","box6": "Click on icon to add text."}';
console.log(st);
var res = JSON.parse(st);
console.log('res' + res.heading);
我沒有收到任何錯誤。 – Xufox
請在一個代碼塊中顯示您的JSON(**,只是**您的JSON),並在另一個代碼塊中顯示您的代碼。現在有什麼是一種混雜的混搭,包括看起來像你的JSON(這將是無效的),所以它很難幫助你。 –
如果我們假設你的JSON是'{'到'}'的一部分而不包括';',那麼JSON就沒問題。 –