0

I am newbie to JSON and Javascript So,help me to find the array values in an object in JSON.Here I hava a JSON Object like this

{
"DefinitionSource": "",
"ImageWidth": 0,
"RelatedTopics": [
{
    "Result": "<a href=\"https://duckduckgo.com/Ashok_Shinde\">Ashok Shinde</a>An Indian film and stage actor, who works in Marathi cinema, known for films like Rangat Sangat.",
    "Icon": {
        "URL": "",
        "Height": "",
        "Width": ""
    },
    "FirstURL": "https://duckduckgo.com/Ashok_Shinde",
    "Text": "Ashok ShindeAn Indian film and stage actor, who works in Marathi cinema, known for films like Rangat Sangat."
},
{
    "Result": "<a href=\"https://duckduckgo.com/R._Ashok\">R. Ashok</a>R. Ashok is a leader of the Bharatiya Janata Party in Karnataka, India.",
    "Icon": {
        "URL": "",
        "Height": "",
        "Width": ""
    },
    "FirstURL": "https://duckduckgo.com/R._Ashok",
    "Text": "R. AshokR. Ashok is a leader of the Bharatiya Janata Party in Karnataka, India."
},
{
    "Result": "<a href=\"https://duckduckgo.com/Ashok_(film)\">Ashok (film)</a>",
    "Icon": {
        "URL": "https://duckduckgo.com/i/37704bcf.jpg",
        "Height": "",
        "Width": ""
    },
    "FirstURL": "https://duckduckgo.com/Ashok_(film)",
    "Text": "Ashok (film)A 2006 Telugu film directed by Surender Reddy."
}
],
"Entity": "",
"Results": [],
"Answer": ""
}

In this JSON i want to get "URL" inside the ICON object and "TEXT" from each object inside "RelatedTopics".. But i was unable to find how. Please help to Get out of this problem. Thanks in advance

0

2 Answers 2

2

You have to loop the array of objects and use the index to check the properties of each:

for (var i = 0; i < data.RelatedTopics.length; i++) {
    console.log(data.RelatedTopics[i].Text); //text;
    console.log(data.RelatedTopics[i].Icon.URL) //url;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you...It is working..Thanks for the fast response.
1

You can also try

results.map(function(e){ return e.Icon.URL; });

Comments

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.