Parsing JSON


Hello All,
Im receiving a JSON response in my IONIC app which looks like this,

[{“id”:“1”,“tid”:“1”,“name”:“Mr Doctor Test”,“age”:“40”,“sex”:“Male”,“exp”:“15”,“speciality”:“Gynecology”,“qualification”:“MBBS”,“title”:“Doctor”,“timings”:“10:00,10:30,11:00,11:30,12:00”}]

How do I extract the timings as an array or object (split comma seperated) and ng repeat over that ? What do I need to do in my controller ?

So basically like < li > {{x.time}} < /li > (10:00 here)
< li > {{x.time}} < /li > (10:30 here) etc


Use split () method on timings string.

var array = string.split(’,’);

This will give you an array of timings you can iterate over.


How do I get the timings node as a string ?


It is already a string.


Let me be more precise, how do I assign it to a string variable ?
As of now I get the entire JSON data as an object. How do I extract only the ‘timings’ node ?
Only after that can I split the string right ?


Assuming the above JSON has already been parsed by Angular into javascript objects, it’s an array so you’ll need to treat it as such. Let’s assume “response” contains the above, parsed by angular.

var timingsString = response[0].timings;
var timings = timingsString.split(','); //Array of the timings

Should be then able to assign it to scope and iterate it over it as usual.


Thank you very much, I got it to work. @tomkuipers @andrewmcgivery


Exactly, thanks for the example @andrewmcgivery