Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am converting DataSet to Json which looks like this (data.d at clientside which is returned to client)
{"patients":[{"name":"sam","id":"1"},{"name":"mark","id":"2"}],"medications":[{"id":"1","medication":"atenolol"},{"id":"2","medication":"amoxicillin"}]}


Now I am trying to get Patient datatable in a variable but I am unable to do so.
I tried
JavaScript
var dt=data.d;

But
JavaScript
dt['patients'] 
gives me undifined.
Posted
Comments
Sanket Saxena 15-Apr-14 8:01am    
Did you tried data.d['patients'] or data.d[patients]

1 solution

Hi Arbaaz,

Actually it is a JSON object not an array so you have to use following:

JavaScript
//First convert your response in JSON object
var dt = JSON.stringify(data.d);

//Now you can access Patients name like
alert(dt.patients[0].name) // it will popup "sam"


Thanks,
Imdadhusen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900