My JSON structure contains multiple values like the following:
[{"Id":22,"Title":"München - Stockholm 31.01.2017 15:00"},{"Id":23,"Title":"Stockholm - München 01.02.2017 18:00"}]
I have successfully split one of them using this code:
var text = "[{\"Id\":22,\"Title\":\"München - Stockholm 31.01.2017 15:00\"}]";
console.log(JSON.parse(text)[0].Title.split(","));
How can I split all elements within the JSON structure?
The approach below works for 2 items, but I want a dynamic solution.
var text = "[{\"Id\":22,\"Title\":\"München - Stockholm 31.01.2017 15:00\"},{\"Id\":23,\"Title\":\"Stockholm - München 01.02.2017 18:00\"}]";
var count = Object.keys(text).length;
console.log(count);
for (var i=0; i < 2; i++){
console.log(JSON.parse(text)[i].Title.split(","));
}
I tried to use the count
variable in the loop, but it gave unexpected results. Any ideas on how to achieve this?
Thank you for your help!