Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read json object when i don`t know the name of the key

in runtime i will have a dynamic dictionary object return to me

e.g var objectFromApi = {"A ":"I am A","B":"I am B","C":"I am C"}

i cannot do objectFromApi ["A"] to get the value, since i won`t able to know the key.

is there a way to print all the key and its value?

is there something like

for(j=0;j<objectFromApi.length;j++)
{
    console.debug(objectFromApi[j].Key +"  " + objectFromApi[j].Value);
}

Thanks

like image 760
jojo Avatar asked Nov 29 '25 04:11

jojo


1 Answers

for(var name in objectFromApi )
{
    if (objectFromApi.hasOwnProperty(name))
    {

    }
}

http://jsfiddle.net/V6t6Y/

like image 191
CD.. Avatar answered Dec 01 '25 18:12

CD..



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!