javascript - Converting String Object to Json Object - Stack Overflow

" {"error":"ApplicationException","reason":"Data types of key c

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

Is stored in string format, I need it in json format

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

Is stored in string format, I need it in json format

Share Improve this question edited Feb 28, 2013 at 7:10 Arun P Johny 388k68 gold badges531 silver badges532 bronze badges asked Feb 28, 2013 at 6:56 Ashwin HegdeAshwin Hegde 8672 gold badges8 silver badges12 bronze badges 2
  • 2 JSON is a string format, so it's already JSON. – Guffa Commented Feb 28, 2013 at 6:57
  • In regards to the various answers here -- if you're trying to decide whether to use JSON.parse or jQuery.parseJSON, you should be aware that the jQuery version is better for cross-browser patibility. See the following post stackoverflow./questions/10362277/… – Aaron Blenkush Commented Feb 28, 2013 at 7:02
Add a ment  | 

5 Answers 5

Reset to default 4

Modern browsers have built in parser JSON.parse(string).

If you have to support older browsers you can add json2/json3 libraries. These will add the JSON.parse support if native support is not present in the browser.

If the string is not valid then a parse error will be thrown, in your case it looks like you may have to escape the 's.

Use

jQuery.parseJSON( json )

example

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

for more info see details

To convert the JSON-string1 to Object, parse it. You should mind escaping apostrophes here:

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

1 JSON: JavaScript Object Notation

You could use something like this

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

You can use (jQuery)

$.parseJSON(STRING);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266638a4619496.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信