如何在多维javascript对象中获取key-dan值

如何在多维javascript对象中获取key-dan值,javascript,json,object,Javascript,Json,Object,我无法使用此JSON获取输出 { status: "ok", query: { format: "JSON", city: "667", date: "2020-10-14" }, schedule: { status: "ok", data: {

我无法使用此JSON获取输出

{
    status: "ok",
    query:
    {
        format: "JSON",
        city: "667",
        date: "2020-10-14"
    },
    schedule:
    {
        status: "ok",
        data:
        {
            prayer1: "14:46",
            prayer2: "05:55",
            prayer3: "11:42",
            prayer4: "04:06",
            prayer5: "18:58",
            prayer6: "17:48",
            prayer7: "04:16",
            prayer8: "Rabu, 14 Oct 2020",
            prayer9: "05:29"
        }
    }
}
我想获取特定的数据键或值(exp.
1

我试过这个密码

Object.keys(JSON).forEach(function (key) {
    console.log(JSON[key].data);
});
但它只输出所有数据,而不是特定的数据

let json = {
   status: "ok",
   query: {
           format: "JSON",
           city: "667",
           date: "2020-10-14"
          },
   schedule: {
            status: "ok",
            data: {
                   prayer1: "14:46",
                   prayer2: "05:55",
                   prayer3: "11:42",
                   prayer4: "04:06",
                   prayer5: "18:58",
                   prayer6: "17:48",
                   prayer7: "04:16",
                   prayer8: "Rabu, 14 Oct 2020",
                   prayer9: "05:29"
                  }
           }
}
Object.keys(json.schedule.data).forEach(key => {
  console.log(json.schedule.data[key])
})

/*
OUTPUT:
14:46
05:55
11:42
04:06
18:58
17:48
04:16
Rabu, 14 Oct 2020
05:29

*/


Repl.it:

如果要从特定键(例如,
1
)获取数据,则无需使用
forEach()

榜样

const data={状态:“ok”,查询:{格式:“JSON”,城市:“667”,日期:“2020-10-14”},时间表:{状态:“ok”,数据:{祈祷1:“14:46”,祈祷2:“05:55”,祈祷3:“11:42”,祈祷4:“04:06”,祈祷5:“18:58”,祈祷6:“17:48”,祈祷7:“04:16”,祈祷8:“拉布,2020年10月14日”,祈祷9:“05:29”}
//搜索
const getKey='prayer1';
//因为我们只需要data.schedule.data
const searchIn=data.schedule.data;
//通过键获取值
const value=searchIn[getKey];

console.log(值)
必须迭代json.schedule.data如果知道路径是什么,可以使用点语法指定它:
var player1data=json.schedule.data.player1
。如果将密钥存储在变量中,则可以将点括号语法组合起来:
var myPlayerData=JSON.schedule.data[playerName]
。除此之外,我真的不知道你在问什么。你可能需要提供更多的信息。。我只是漏掉了一个单词。。谢谢你的回答。实际上,上面的代码输出与
data.schedule.data.prayer1
oh myyy。。我只是错过了一个字……)是的,这是同样的想法。我只是用不同的步骤来回答,这样可以更清楚地知道步骤是什么。。非常感谢您的回复。。我很感激