PDA

View Full Version : read result from jsonp request with a unknown propery



simiita
23 Jun 2011, 4:01 AM
hello :)

i got a problem with my jsonp.request result

this is my result from the jsonp.request:

Ext.util.JSONP.callback({
"success":true,
"BaReq":{
"results":"5",
"columns":"1",
"rows":[
{
"LIC_NO":"376103021000005378"
},
{
"LIC_NO":"376103021000005453"
},
{
"LIC_NO":"376103021000005491"
},
{
"LIC_NO":"376103021000005569"
},
{
"LIC_NO":"376103021000005583"
}
]
}
})now i like the alert the first entry like this


alert('result: ' + result.BaReq.rows[1].LIC_NO);my problem is, that it's not always LIC_NO, is there a possibility to find out "LIC_NO" or what ever it is..

thanks for any help :D

simiita
30 Jun 2011, 11:46 PM
no ideas? would be very nice, if someone could give me a help :-?

Hanni Sullivan
1 Jul 2011, 12:17 AM
I might missing your point entirely but you just want to know whether a certain property exists?
Please follow me to stackoverflow.com (http://stackoverflow.com/questions/3390396/best-way-to-check-for-undefined-in-javascript)

simiita
1 Jul 2011, 12:43 AM
First, thanks for your comment. ;)

My problem is: I don't know what I'll get in my result; so I need to get a list of all property names. In my example I do not know "LIC_NO". But target is to read property name and its value of property "LIC_NO" to popoulate a list.

Is it possible to fill all elements in an array or so? Or get name of property using a position number? E.g. get element name at position 0?

Thanks

Hanni Sullivan
1 Jul 2011, 1:42 AM
How about this?



function getRowProperties(rows) {
var allProperties = {};
/* iterate over your whole rows array
and execute the function for each entry
*/
Ext.each(rows, function(row, index) {
/* This array will hold all property names
of the current row
*/
var namesOfAllProperties = [];
// We iterate over all properties of the row
for (property in row) {
// and store the name of each property
namesOfAllProperties.push(property);
}
// The array with the property names is stored in our object
allProperties[index] = namesOfAllProperties;
});
return allProperties;
}
/*
Usage:
>var list = getRowProperties(rows);
Get the list of all properties of the second row:
> list[1]
> ["LIC_NO"]

Get the first property of the second row:
> list[1][0]
> "LIC_NO"

*/

simiita
4 Jul 2011, 3:14 AM
This helped me very much. Thank you :)

:D