0
映射我有一个问题想分析JSON文件JSON对象
我的JSON文件的形式下:
GSON解析JSON对象从一个复杂的JSON文件
{ "objectJSON": [
{
"attribute":"value",
"attribute":"value",
"attribute":"value",
"attributes" :{
"att1": "val1",
"att2":"val2",
"att3":"val3",
// more atts and vals may figure here !
}
},
{
"attribute":"value",
"attribute":"value",
"attribute":"value",
"attributes" :{
"att1": "val1",
"att2":"val2",
"att3":"val3",
// more atts and vals may figure here !
}
}
]
}
我的问题是,对象“属性”有一个参数数目未知的,所以我不能为它创建一个类,我想过使用
map<String,String> attributes;
,但我不知道如何从文件中解析它特别,我想让我的班级“ObjectJSON”女巫代表th我的文件的根目录。
我使用谷歌的gson
在此先感谢。
不能使用的HashMap <字符串,对象>? – Poppy
查看:'Google Gson','org.json'库,Jackson库,JSR-374 Json API。每一个你可以自由使用的(也许除了org.json之外,因为它比较陈旧而且很硬,虽然比较起来也很轻巧)。 –
如果您没有重复的“属性”:“值”条目,则会更清楚。它看起来像这个结构对应于一个具有类型为List