2013-02-28 73 views
0

" {"error":"ApplicationException","reason":"Data types of key columns do not match. 'USERS.lastmodifiedtime' is of 'TIMESTAMP', 'state_list.name' is of 'VARCHAR'."} "转换字符串对象到JSON对象

是存储在字符串格式,我需要它以JSON格式

+2

JSON是一个字符串格式,所以它的已经是JSON。 – Guffa 2013-02-28 06:57:50

+0

关于这里的各种答案 - 如果您试图决定是使用JSON.parse还是jQuery.parseJSON,您应该知道jQuery版本更适合跨浏览器兼容性。看到下面的帖子http://stackoverflow.com/questions/10362277/jquery-parsejson-vs-json-parse – 2013-02-28 07:02:58

回答

2

使用

jQuery.parseJSON(json)

例如

var obj = jQuery.parseJSON('{"error":"ApplicationException"}'); 

$.parseJSON(STRING); 
0

你可以使用类似这样

var obj = jQuery.parseJSON('{"error":"ApplicationException"}'); 
0

可以使用(jQuery的)。

如果你要支持旧的浏览器,您可以添加json2/json3库。如果本机支持不在浏览器中,这些将添加JSON.parse支持。

如果该字符串不是有效的,则解析错误将被抛出,在你的情况下,它看起来像你可能有逃避'秒。

2

到JSON- 转换为Objectparse它。你应该介意这里转义单引号:

JSON.parse('{"error":"ApplicationException","reason":"Data types of key columns do not match. \'USERS.lastmodifiedtime\' is of \'TIMESTAMP\', \'state_list.name\' is of \'VARCHAR\'."}') 

JSON:Ĵ AVA 小号 CRIPT Ø bject ň浮选