0

I have a JSON object returned in my console, and I want to display those data named "offers".

the JSON object is returned like that :

enter image description here

I tried to display my JSON Object data with :

console.log(JSON.stringify(data));

The thing is, it says that "data is not defined"

Does anyone know what happens ? :)

2 Answers 2

1

You should add full path to element of json, for example if your json looks like:

var json = {"par":22, "par2":555, "elems":[{"attr1":53, "attr2":99}] };

and if you want to get attr1 value, you should do something like this:

console.log(json.elems[0].attr1); // 53

so in your case that could be something like:

variableName.result.data.offers //variableName is variable that your "consoling"

Method JSON.stringify doesn't get yout specified value from JSON structure, it's converts JSON object to string.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I am not sure to understand what is the variableName ?
This is that thing that you shows on console. For example if that what you show in picture is given by console.log(result), variableName will be result. So you should find in your code, what causes printing object to developer console.
1

console.dir provides a good representation of object than console.log().U can try with both

console.log(result.data.offers[0]);
console.dir(result.data.offers[0]);

1 Comment

it still says that "result is not defined"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.