How can I transform the following string into an object?
{src:'img/testimage.jpg', coord : {x:17, y:39}, width:200, height, 200}
Update:
I have a PHP file that generates JSON output. I used AJAX to retrieve the JSON in my JavaScript.
By using JSON.parse(json_string), I now have my object. This is the result:
[{"name":"img","attributes":"{src:'img\/testimage.jpg', coord : {x:17, y:39}, width:200, height: 200}","comments":"image element with attributes"},{"name":"triangle","attributes":"{bgColor : '#FF0000', coord : {x:500, y:300}, width:50, height: 50}","comments":"triangle"}]
Now, I can iterate through the elements using a for loop.
for(key in json_object) {
var name_type = json_object[key].name;
var attrib = json_object[key].attributes;
}
When attrib is logged, it shows:
{src:'img/testimage.jpg', coord : {x:17, y:39}, width:200, height, 200}.
I need to convert this string into an object.
Thank you, Dave