I have a string
{ city : Chicago , country : us , name : Somebody , plan : quarter90wtrial },{ city : New York , country : us , name : Somebody , plan : quarter90wtrial },{ city : Portland , country : us , name : Somebody , plan : quarter90wtrial },{ city :null, country :null, name : Somebody , plan : quarter90wtrial },{ city : Mexico City , country : mx , name : Aaron , plan : quarter90wtrial },{ city : Boston , country : us , name : Somebody , plan : quarter90wtrial },{ city : Los Angeles , country : us , name : Somebody , plan : quarter90wtrial },{ city : London , country : gb , name : Aaron , plan : quarter90wtrial },{ city : Los Angeles , country : us , name : Aaron , plan : quarter90wtrial },{ city : Chicago , country : us , name : Aaron , plan : quarter90wtrial }
What I am trying to do is turn this string into an object where I can iterate and print out the city, country, and name for each one. So far I have figured out how to split the string to print out each line individually.
str = str.split('},{');
for(var i =0; i < str.length; i++)
{
alert(str[i]);
}
What I cannot figure out is how to convert the string to an object where I can print out the city, country, name, etc.
JSON.parse. What creates this string? Any chance you make it produce JSON? That would be the best solution.[]without which it is not valid json