Best way to convert string to array of object in javascript?

后端 未结 6 1272
萌比男神i
萌比男神i 2020-11-27 19:21

I want to convert below string to an array in javascript.

{a:12, b:c, foo:bar}

How do I convert this string into array of objects? Any cool

6条回答
  •  渐次进展
    2020-11-27 19:38

    If you're using jQuery, there's the $.parseJSON() function. It throws an exception if the string is malformed, and "Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON. Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string"

提交回复
热议问题