json如下,只是小部分,后面还有CDEF想把result解析为list结构
{
"reason": "成功返回",
"result": {
"A": [
{
"id": "2000386",
"big_ppname": "AC",
"pin": "A"
},
{
"id": "2000142",
"big_ppname": "阿尔法-罗密欧",
"pin": "A"
}
],
"B": [
{
"id": "2000194",
"big_ppname": "奔驰",
"pin": "B"
},
{
"id": "2000198",
"big_ppname": "标致",
"pin": "B"
}
]
},
"error_code": 0
}求大神告知如何把这段json转化为实体类,把result转为list
{
"reason": "成功返回",
"result": {
"A": [
{
"id": "2000386",
"big_ppname": "AC",
"pin": "A"
},
{
"id": "2000142",
"big_ppname": "阿尔法-罗密欧",
"pin": "A"
}
],
"B": [
{
"id": "2000194",
"big_ppname": "奔驰",
"pin": "B"
},
{
"id": "2000198",
"big_ppname": "标致",
"pin": "B"
}
]
},
"error_code": 0
}求大神告知如何把这段json转化为实体类,把result转为list
解决方案 »
- android上的播放器,一般怎么输出视频?surface
- 关于listview
- 请教创建Android程序时桌面快捷图标会在第几屏?
- 录音问题
- 想写个android平台的彩信阅读软件,该从何下手啊?
- 两个Activity之间怎么传递List<Map<String,Object>>型数据,谢谢
- 程序打包安裝到手機上的問題
- 关于wifi模块wifi连接状态显示的问题
- 请教JNI调用的C程序常驻内存方法
- Unable to start activity ComponentInfo{**} java.lang.NullPointerException
- Android-support-v4 jar包
- 求助!!!Android Studio通过JNI使用C代码,在构建时出现图内错误,该如何解决
private String reason;
private List<TBean> result;
private int error_code; public String getReason() {
return reason;
} public void setReason(String reason) {
this.reason = reason;
} public List<TBean> getResult() {
return result;
} public void setResult(Map<String, List<TBean>> map) {
this.result = new ArrayList<>();
if (map != null) {
for (Map.Entry<String, List<TBean>> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
if (entry.getValue() != null){
result.addAll(entry.getValue());
}
}
}
} public int getError_code() {
return error_code;
} public void setError_code(int error_code) {
this.error_code = error_code;
} public static class TBean {
private String id;
private String big_ppname;
private String pin; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getBig_ppname() {
return big_ppname;
} public void setBig_ppname(String big_ppname) {
this.big_ppname = big_ppname;
} public String getPin() {
return pin;
} public void setPin(String pin) {
this.pin = pin;
}
}
}我用的fastjson解析
测试代码TestBean testBean = JSON.parseObject(str,TestBean.class);
Log.d("TestBean", JSON.toJSONString(testBean));日志输出D/TestBean: {"error_code":0,"reason":"成功返回","result":[{"big_ppname":"奔驰","id":"2000194","pin":"B"},{"big_ppname":"标致","id":"2000198","pin":"B"},{"big_ppname":"AC","id":"2000386","pin":"A"},{"big_ppname":"阿尔法-罗密欧","id":"2000142","pin":"A"}]}