通过值识别json键并提取所有匹配项

时间:2019-08-10 16:30:45

标签: r json

我有一个json文件,我有一个要提取的值之一。我的目标是提取与样本值共享同一键的所有值。

样本数据:

(从这里开始:https://support.oneskyapp.com/hc/en-us/articles/208047697-JSON-sample-files

foo

假设我的值是“哪个是NBA中正确的球队名称?”我如何以编程方式找到相应的密钥,以使用它来提取共享同一密钥的值。

所需的输出:

查找键: Key1:“问题”

Key2:“测验,运动,第一题,问题”

然后找到共享相同密钥的值:

{ "quiz": { "sport": { "q1": { "question": "Which one is correct team name in NBA?", "options": [ "New York Bulls", "Los Angeles Kings", "Golden State Warriros", "Huston Rocket" ], "answer": "Huston Rocket" } }, "maths": { "q1": { "question": "5 + 7 = ?", "options": [ "10", "11", "12", "13" ], "answer": "12" }, "q2": { "question": "12 - 8 = ?", "options": [ "1", "2", "3", "4" ], "answer": "4" } } } }

0 个答案:

没有答案