I would like to convert this string
{"id":1,"name":"Test1"},{"id":2,"name":"Test2"}
to array of 2 JSON objects. How should I do it?
best
I would like to convert this string
to array of 2 JSON objects. How should I do it? best |
|||||
|
Using jQuery:
|
|||
Append extra an You should use https://github.com/douglascrockford/JSON-js instead of |
|||
|
as Luca indicated, add extra [] to your string and use th code below... var myObject = eval('(' + myJSONtext + ')'); to test it you can use the snippet below.
hope it helps.. |
||||
|
If your using jQuery, it's parseJSON function can be used and is preferable to JavaScript's native |
|||
|
I know a lot of people are saying use eval. the eval() js function will call the compiler, and that can offer a series of security risks. It is best to avoid its usage where possible. The parse function offers a more secure alternative. |
|||
|