为什么我的json无法转换为字符串
Why is my json unable to be converted to a string?
我有一个函数可以获取远程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 ....
删除Devlin
中D
之前的换行符/换行符,则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>",
相关文章:
- 如何使用JQuery在Javascript中转换字符串中的HTML元素
- 将JSON插入MongoDB中,自动转换字符串中的日期
- 以点表示法转换字符串以获取对象引用
- 在 JavaScript 中转换字符串 11/28/2014 11:00 AM 到现在
- 为什么在主干的字符串数组中转换字符串数组
- 如何简单地转换字符串
- AngularJS如何转换字符串“;yyyyMMdd”;迄今为止
- 如何防止htmlspecialchar(PHP)转换字符串中的整数
- 刷新Aurelia中的i18n转换字符串插值
- 发布时禁用转换字符串
- 转换字符串货币
- 在javascript ajax调用中转换字符串到数组
- 转换字符串包含时间到24小时的时间,我可以做数学与- jQuery
- IE javascript引擎在转换字符串到日期时呈现NaN
- 如何转换字符串“a,b,c,d……”成a.b (c, d . .);来执行
- 如何在javascript中转换字符串到日期格式
- 如何在嵌套数组中转换字符串数组
- 在javascript中转换字符串日期
- 转换字符串在印度格式的javascript
- Javascript转换字符串到数组的对象