In Javascript, I have a string that I need to convert to an Array of objects.
//ORIGINAL STRING :
var originalString = "[13, "2017-05-22 17:02:56", "Text111"], [25, "2017-05-22 17:03:03", "Text222"], [89, "2017-05-22 17:03:14","Text333"]";
I need to be able to loop through each object, and get the 3 properties by using indexes. That would give (for the first Array) :
myItem[0] => 13
myItem[1] => "2017-05-22 17:02:56"
myItem[2] => "Text111"
That first sounded simple to my head (and probably is), but after several attempts, I am still stuck.
Please note that I cannot use jQuery because running with a very old Javascript specification : "Microsoft JScript", which is EcmaScript 3 compliant.
I thank you ;)
originalStringcode will throw errors due to invalid JS syntax. Are you missing quote escaping?evalit. Why are you using such an old version anyway? If you updated to at least 5.1 then you could useJSON.parse.originalStringcontains", and this is not correct. The fact is that this string is returned AS IS by an external API (such a shame). @Andrew Li : I CAN use JSON.parse (I have implemented a JS port of it, and it is fully functional).JSON.parse()yourself rather than including the original json2.js that Mr Crockford implemented years ago?