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
As Luca indicated, add extra [] to your string and use the code below:
var myObject = eval('(' + myJSONtext + ')');
to test it you can use the snippet below.
var s =" [{'id':1,'name':'Test1'},{'id':2,'name':'Test2'}]";
var myObject = eval('(' + s + ')');
for (i in myObject)
{
alert(myObject[i]["name"]);
}
hope it helps..