为什么我的json无法转换为字符串

Why is my json unable to be converted to a string?

本文关键字:转换 字符串 我的 json 为什么      更新时间:2023-09-26

我有一个函数可以获取远程JSON,但我认为JSON格式不好,所以我不能在上面使用JSON.stringify方法。我认为这是因为其中一些函数中包含撇号。我无法访问服务器。有没有一种方法可以解析和更改json,以便正确格式化所有远程提取的json?

这就是现在的格式。

var jsonst = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's  Dilemma","guest":"Devin Rose","category":"Non-Catholic","url":"http://www.catholic.com /radio/shows/the-protestants-dilemma-11565","audiourl":"http://www.catholic.com/sites /default/files/audio/radioshows/ca140331b.mp3","datetime":"1396317600","description":"
Devin Rose grew up a militant's<'/p>","thumbnailsmall":"http://www.catholic.com/sites/default/files/imagecache/profile_square_small/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg","thumbnaillarge":"http://www.catholic.com/sites/default/files/imagecache/profile_square_large/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg"}]}
var = jsonstring = JSON.stringify(jsonst);
alert(jsonstring);

类型:

var = jsonstring

用代替

var jsonstring

此外,我在你的变量jsonst:中得到了一个SyntaxError: Unexpected token ILLEGAL

变量中似乎有一个换行符:

"description":"
Devin Rose grew up ....

删除DevlinD之前的换行符/换行符,则jsonstring变量将被完全填充:

"{"shows":[{"show_id":6387,"shownum":6387,"title":"The Protestant's  Dilemma","guest":"Devin Rose","category":"Non-Catholic","url":"http://www.catholic.com /radio/shows/the-protestants-dilemma-11565","audiourl":"http://www.catholic.com/sites /default/files/audio/radioshows/ca140331b.mp3","datetime":"1396317600","description":"Devin Rose grew up a militant's</p>","thumbnailsmall":"http://www.catholic.com/sites/default/files/imagecache/profile_square_small/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg","thumbnaillarge":"http://www.catholic.com/sites/default/files/imagecache/profile_square_large/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg"}]}"

description键的值引发解析错误。不要有换行符。只有"description": "Devin Rose grew up a militant's</p>", 而不是"description": " Devin Rose grew up a militant's</p>",