【发布时间】:2016-09-28 14:07:19
【问题描述】:
您好,我正在尝试解析简单的 json(string),但出现错误。 这是我需要得到的对象
{
"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.======== ","box6": "Click on icon to add text."}';
console.log(st);
var res = JSON.parse(st);
console.log('res' + res.heading);
【问题讨论】:
-
我没有收到任何错误。
-
请在一个代码块中显示您的 JSON(只是您的 JSON),并在另一个代码块中显示您的代码。现在有一个大杂烩,包括
;似乎是您的 JSON(这将是无效的),因此很难为您提供帮助。 -
如果我们假设您的 JSON 是从
{到}的部分并且不包括;,那么 JSON 就可以了。 -
等号后面的空白字符串是什么?是一连串的回车吗?这会破坏 JSON
-
@abosancic:不要试图把它放在评论中,使用问题上的“编辑”链接。但同样,它工作得很好,所以这显然不是您遇到问题的实际 JSON。
标签: javascript jquery json