Javascript 使用dojo显示Json数据
我正在构建Dojo移动应用程序。我有一个Json文件,如:Javascript 使用dojo显示Json数据,javascript,html,json,dojo,web,Javascript,Html,Json,Dojo,Web,我正在构建Dojo移动应用程序。我有一个Json文件,如: { Introduction: [ { title: "Introduction", toolbar: "Page 1", content: "cont, aabitant morbi tristique..." }, { title: "Introduction",
{
Introduction:
[
{
title: "Introduction",
toolbar: "Page 1",
content: "cont, aabitant morbi tristique..."
},
{
title: "Introduction",
toolbar: "Page 2",
content: "contesent vel nisi ipsum..."
}
],
Services:
[
{
title: "services",
toolbar: "Page 1",
content: "Cras adipiscing sapien nec..."
}
]
}
下面的代码打印标题中所写的简介
dojo.xhrPost({
url: "diet.json",
handleAs: "json",
load: function(response) {
console.log(response.Introduction[0].title);
}
});
我能够获得内部数据。如何获取第一个标题,即
- 导言
- 服务
for (key in response)
console.log(key + ": " + response[key][0].title);
当然,这假设响应中的每个数组中至少有一个元素。如果其中一些可能是空的,则您可能需要以下内容:
for (key in response)
console.log(key + ": " +
(response[key].length > 0 ? response[key][0].title : "empty"));
假设我不知道服务。我怎样才能得到服务?