PDA

View Full Version : Retrieve data from Json array



shobhaaradhya
3 Aug 2012, 12:48 AM
Hi,

var d = Ext.util.JSON.decode(r.responseText);

d has data object which holds 3 set of data (array). Each set had

id
firstname
lastname
designation
salary
optionid

How to retrieve optionid from first set only


Thanks in Advance

sword-it
3 Aug 2012, 4:26 AM
I think your json data (d) is like this:


{
"0":{
id:'xxxx'
, firstname:'xxxx'
, lastname:'xxxx'
, designation:'xxxx'
, salary:'xxxx'
, optionid:'xxxx'
},
"1":{
id:'xxxx'
, firstname:'xxxx'
, lastname:'xxxx'
, designation:'xxxx'
, salary:'xxxx'
, optionid:'xxxx'
},
"2":{
id:'xxxx'
, firstname:'xxxx'
, lastname:'xxxx'
, designation:'xxxx'
, salary:'xxxx'
, optionid:'xxxx'
}
}

So you can get optionid from first set only like this:
d['0']['optionid']...

shobhaaradhya
6 Aug 2012, 12:02 AM
Hi,
Thanks for your reply,

I tried using
d['0']['optionid'] but could not get the value


When I check script from firefox by debugging i could see structure of d something like below mentioned. Not sure whether something to do with 'data' also.


d
data [......................]
0 [..............]
1 [..............]
2 [..............]


Please help me. I am using extjs 3.x version

Thanks,

willigogs
6 Aug 2012, 12:33 AM
Could you console.log your "d" variable and share with us the output?

sword-it
6 Aug 2012, 1:26 AM
Hi

i guess "optionid" is under data array try this


d.data[0]["optionid"]

Regards

shobhaaradhya
10 Aug 2012, 11:30 PM
hi,

thanks its working...