【发布时间】:2021-12-12 13:02:17
【问题描述】:
我有一个包含大量数据的 JSON,下面是它的一个示例:
{
"type":"doc",
"content":[
{
"type":"paragraph",
"content":[
{
"text":"this is a simple page, about a simple umbrella.",
"type":"text"
}
]
},
{
"type":"paragraph",
"content":[
{
"text":"you can use this text to find the umbrella page.",
"type":"text"
}
]
},
{
"type":"paragraph",
"content":[
{
"text":"do you like it?",
"type":"text"
}
]
}
}
我想提取text键的值,不管键在哪里。我正在尝试使用 Object.keys 遍历键,但它只返回顶级键:
for (let x of Object.keys(someJson)) {
console.log(x);
}
我如何在这个 JSON 中找到 所有text 的值,无论它在 JSON 中的哪个位置?
【问题讨论】:
-
你需要使用递归
标签: json typescript