最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Converting String Object to Json Object - Stack Overflow

programmeradmin0浏览0评论

" {"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);
发布评论

评论列表(0)

  1. 暂无评论