想要解析下面的JSON。这里dynamic1和dynamic2分别根据“id”和“idext”中的值而变化。在运行时,我们可以获得它的任何值。由于我发现定义json模式有困难,因为节点是动态的,如何通过json解析来从json消息中提取值。
{
"id":"dynamic1",
"idext":"dynamic2",
"details":{
"description":"this is the description",
"dynamic1":{ <-- this would change based on the value in 'id'
"param1":"100",
"param2":"101",
"param3":"102"
},
"dynamic2":{ <-- this would change based on the value in 'idext'
"param4":"200",
"param5":"201",
"param6":"202"
},
}
}
Id和idext可以是运行时的任何东西,使得完整的JSON内部对象是动态的,如下所示......在运行时可能就像字面意思一样。如何定义一个Jason parsor来提取完整的对象甚至在对象内,如param1,param2,param3,param4,param5,param6
{
"id":"john",
"idext":"peter",
"details":{
"description":"this is the description",
"john":{ <-- this would change based on the value in 'id'
"param1":"100",
"param2":"101",
"param3":"102"
},
"peter":{ <-- this would change based on the value in 'idext'
"param4":"200",
"param5":"201",
"param6":"202"
},
}
}
提前致谢... 约翰