我希望能够在JavaScript中遍历整个JSON并找到从特定键开始的值。 假设这是我的JSON数据:
var data = {
"array": [
1,
2,
3
],
"boolean": true,
"null": null,
"number": 123,
"object": {
"a": "b",
"abc":{
"mohit_ab": {
"id1":"i am id 1",
"abcd":{
"a" :"b",
"c":"d"
},
"who" : "who are you",
"id2":"i am id 2"
},
"mohit_231abcd": {
"id1":"i am id 3",
"identity" : "i am real mohit",
"id2":"i am id 4"
}
},
"hji":{
"mohit_adss231": {
"id1":"i am id 5",
"identity" : "i am mohit in real",
"id2":"i am id 6"
},
"mohit": {
"id7":"i am id 7",
"identity" : "i am mohit and you?",
"id8":"i am id 8"
}
},
"c": "d",
"e": "f"
},
"string": "Hello World"
};
我希望能在JavaScript中解析完整的JSON,并获取键以“mohit”开头的值。例如,上面输入的输出为:
valueableData:{
"mohit_ab": {
"id1":"i am id 1",
"abcd":{
"a" :"b",
"c":"d"
},
"who" : "who are you",
"id2":"i am id 2"
},
"mohit_231abcd": {
"id1":"i am id 3",
"identity" : "i am real mohit",
"id2":"i am id 4"
},
"mohit_adss231": {
"id1":"i am id 5",
"identity" : "i am mohit in real",
"id2":"i am id 6"
},
"mohit": {
"id7":"i am id 7",
"identity" : "i am mohit and you?",
"id8":"i am id 8"
}
}
请为我提供实现此目标的简单方法。