【发布时间】:2014-06-10 03:52:35
【问题描述】:
如果我有一个从 JSON 解析的 Javascript 对象,它嵌套了三层,而我不知道中间那个的键,我如何访问它及其内容?
我使用的实际数据来自 Github API。对于这个例子,我想要所有要点的文件名。
[
{
"url": "https://api.github.com/gists/11164200",
"forks_url": "https://api.github.com/gists/11164200/forks",
"commits_url": "https://api.github.com/gists/11164200/commits",
"id": "11164200",
"git_pull_url": "https://gist.github.com/11164200.git",
"git_push_url": "https://gist.github.com/11164200.git",
"html_url": "https://gist.github.com/11164200",
"files": {
"testing.md": {
"filename": "testing.md",
"type": "text/plain",
"language": "Markdown",
"raw_url": "https://gist.githubusercontent.com/omphalosskeptic/11164200/raw/3582779a4925ea514382cedb7d077d00c231f3eb/testing.md",
"size": 4254
}
}, // [ ... continues]
我的 Javascript 技能还很初级。通常我可以通过足够的研究找到我正在寻找的东西,但这次不行。最初我预计它会类似于:responseObj[0].files[0].filename。
如果可能的话,我想保留这个简单的 Javascript。
谢谢!
【问题讨论】:
标签: javascript json object github github-api