+ 1
Json.parse and ajax returning object object help
im learning json and ajax from a tutorial and for some reason im getting back object object instead of the info i am requesting. am I missing something? https://code.sololearn.com/WHcxhP8sHDo1/?ref=app
6 Respostas
+ 2
because it is an object, if you want to see then entire object as string use JSON.stringify(yourObject)
or directly access a single element in that object
+ 5
Jason Kennedy [object object ], means you are returned an object, if u see this output in chrome, you could have seen the entire object, but in mobile console it gives like that. so your data is there but u have to know its Structure to use it.
PRO TIP : if u wish to see the Structure then use Stringify with these options (null, indentation) , it ll indent the output and helps to see the Structure more clearly
console.log(JSON.stringify(ourdata, null,4));
Now since you know the Structure you can use it directly as shown by calvin
+ 3
console.log(ourdata[2].name);
console.log(ourdata[2].species);
+ 2
your data are returned as an object.
stringify help you to see the entire data so you can access the data yourself using Calvin's example above.
all the data you want is in the object.
+ 1
to TASTY: stringify isnt the issue. the info being called is an object..i want the object..i just want the data from that full object. stringify just returns a backslash.
to CALVIN: as to .name or .species that works but im trying to have it return the full object and data in one command. it should return name species favorire food etc
+ 1
i get it now! i was putting stringify in wrong place before thats why it only showed a back slash. i was replacing json.patse with json.stringify instead of putting stringify in the console.log like morpheus says.
thank you all for the help! you are all correct abd helped me greatly thank you