Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中解析JSON以获取对象内部数组中的值_Javascript_Arrays_Json_Parsing - Fatal编程技术网

在javascript中解析JSON以获取对象内部数组中的值

在javascript中解析JSON以获取对象内部数组中的值,javascript,arrays,json,parsing,Javascript,Arrays,Json,Parsing,我是JSON和Javascript的新手,所以,请帮助我在JSON中查找对象中的数组值 { "DefinitionSource": "", "ImageWidth": 0, "RelatedTopics": [ { "Result": "<a href=\"https://duckduckgo.com/Ashok_Shinde\">Ashok Shinde</a>An Indian film and stage actor, who works in Marath

我是JSON和Javascript的新手,所以,请帮助我在JSON中查找对象中的数组值

{
"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": ""
}
{
“定义来源”:“,
“图像宽度”:0,
“相关主题”:[
{
“结果”:“一位在马拉地电影公司工作的印度电影和舞台演员,因《兰加特·桑加特》等电影而闻名。”,
“图标”:{
“URL”:“,
“高度”:“,
“宽度”:”
},
“FirstURL”:”https://duckduckgo.com/Ashok_Shinde",
“文本”:“Ashok ShindeAn印度电影和舞台演员,在马拉地电影院工作,因《兰加特·桑加特》等电影而闻名。”
},
{
“结果”:“R.Ashok是印度卡纳塔克邦印度人民党的领导人。”,
“图标”:{
“URL”:“,
“高度”:“,
“宽度”:”
},
“FirstURL”:”https://duckduckgo.com/R._Ashok",
“文本”:“R.AshokR.Ashok是印度卡纳塔克邦印度人民党的领导人。”
},
{
“结果”:“结果”,
“图标”:{
“URL”:”https://duckduckgo.com/i/37704bcf.jpg",
“高度”:“,
“宽度”:”
},
“FirstURL”:”https://duckduckgo.com/Ashok_(电影)",,
“文本”:“Ashok(film)2006年由Surender Reddy导演的泰卢固语电影。”
}
],
“实体”:“,
“结果”:[],
“答复”:”
}

在这个JSON中,我想在图标对象中获取“URL”,并从“RelatedTopics”中的每个对象中获取“文本”。。但我找不到该怎么做。请帮我摆脱这个问题。提前感谢

您必须循环对象数组并使用索引检查每个对象的属性:

for (var i = 0; i < data.RelatedTopics.length; i++) {
    console.log(data.RelatedTopics[i].Text); //text;
    console.log(data.RelatedTopics[i].Icon.URL) //url;
}
for(var i=0;i
您必须循环对象数组,并使用索引检查每个对象的属性:

for (var i = 0; i < data.RelatedTopics.length; i++) {
    console.log(data.RelatedTopics[i].Text); //text;
    console.log(data.RelatedTopics[i].Icon.URL) //url;
}
for(var i=0;i
您必须循环对象数组,并使用索引检查每个对象的属性:

for (var i = 0; i < data.RelatedTopics.length; i++) {
    console.log(data.RelatedTopics[i].Text); //text;
    console.log(data.RelatedTopics[i].Icon.URL) //url;
}
for(var i=0;i
您必须循环对象数组,并使用索引检查每个对象的属性:

for (var i = 0; i < data.RelatedTopics.length; i++) {
    console.log(data.RelatedTopics[i].Text); //text;
    console.log(data.RelatedTopics[i].Icon.URL) //url;
}
for(var i=0;i
您也可以尝试

results.map(function(e){ return e.Icon.URL; });
你也可以试试

results.map(function(e){ return e.Icon.URL; });
你也可以试试

results.map(function(e){ return e.Icon.URL; });
你也可以试试

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

谢谢你…它正在工作…谢谢你的快速响应。谢谢你…它正在工作…谢谢你的快速响应。谢谢你…它正在工作…谢谢你的快速响应。谢谢你…它正在工作…谢谢你的快速响应。