80,351
社区成员
发帖
与我相关
我的任务
分享
public class TestBean {
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"}]}