{"zhongtong":"中通","suer":"速尔","bjemstckj":"北京EMS","yuantong":"圆通","ztky":"中铁物流","quanfengkuaidi":"全峰","youshuwuliu":"优速","shentong":"申通","zhaijisong":"宅急送","zhongtiewuliu":"中铁快运","ems":"EMS","shunfeng":"顺丰","guotongkuaidi":"国通","jd":"京东","zengyisudi":"增益","huitongkuaidi":"汇通","tiantian":"天天","yunda":"韵达","ganzhongnengda":"能达","debangwuliu":"德邦","youzhengguonei":"包裹\/平邮"}
解析以上格式的json是,有些人会很苦恼;
但是由于项目需求,所以在网上找了找!
解决方法如下:
将返回的数据用String接收
1.String jsonby= {"zhongtong":"中通","suer":"速尔","bjemstckj":"北京EMS","yuantong":"圆通","ztky":"中铁物流","quanfengkuaidi":"全峰","youshuwuliu":"优速","shentong":"申通","zhaijisong":"宅急送","zhongtiewuliu":"中铁快运","ems":"EMS","shunfeng":"顺丰","guotongkuaidi":"国通","jd":"京东","zengyisudi":"增益","huitongkuaidi":"汇通","tiantian":"天天","yunda":"韵达","ganzhongnengda":"能达","debangwuliu":"德邦","youzhengguonei":"包裹\/平邮"};
2.创建接收集合
ArrayList
3.最重要的一步
Iterator
String key;
Object value;
while (keys.hasNext()) {
key = (String) keys.next();
value = jsonby.get(key);
mList.add(new Logistics(key, (String) value));
}
4.循环结束后此时list集合就包含了以上所有内容
附上:Logistics类的代码
public class Logistics {
public String abb;// 简称
public String name;// 名称
public Logistics(String abb, String name) {
super();
this.abb = abb;
this.name = name;
}
public String getAbb() {
return abb;
}
public void setAbb(String abb) {
this.abb = abb;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}