多层json解析

JSON数据格式{"data":[{"id":"1134","name":"中石油加油站 (建港邮政所西南)","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区鹦鹉大道火车道南侧","brandname":"中石油","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.25006,30.516361","lon":"114.25649912071","lat":"30.522662167959","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":10203},{"id":"8895","name":"中石化琴台加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区琴台路49号,琴台大道与江城大道交叉","brandname":"中石化","type":"直营店","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.250105,30.555689","lon":"114.25651172095","lat":"30.561981100464","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":10258},{"id":"52166","name":"江钻邓甲村天然气加气站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区马鹦路与江腾苑路交叉处,中青假日酒店附近","brandname":"不详","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.2450171803,30.531668884","lon":"114.257943","lat":"30.544322","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":null,"fwlsmc":"","distance":9862},{"id":"53486","name":"道达尔加油站","area":"430033","areaname":"湖北省 武汉市 硚口区","address":"湖北省武汉市硚口区硚口路与仁寿路交叉处,东辉花园对面","brandname":"不详","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.2517841979,30.5741290141","lon":"114.25819031949","lat":"30.580404505826","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"","distance":10760},{"id":"52165","name":"中石油马鹦路加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区马鹦路与江腾苑路交叉处,中青假日酒店附近","brandname":"中石油","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.2453546712,30.5315844542","lon":"114.258255","lat":"30.544189","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":9831},{"id":"8270","name":"中石化金家墩加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市江汉区银墩街,武汉邮政局附近","brandname":"中石化","type":"直营店","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.251981,30.612361","lon":"114.25841829676","lat":"30.618641616727","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":13064},{"id":"51463","name":"中石油金家墩加油站","area":"430040","areaname":"湖北省 武汉市 江汉区","address":"湖北省武汉市江汉区银墩路与银墩街交叉处,湖北邮政全夜航速递局附近 ","brandname":"中石油","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.251983975,30.6154153127","lon":"114.25842360375","lat":"30.621697203353","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":13291},{"id":"49927","name":"道达尔常青路加油站","area":"430040","areaname":"湖北省 武汉市 江汉区","address":"湖北省武汉市江汉区常青路35号,常青路与云彩路交叉口以西方向","brandname":"道达尔","type":"直营店","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.253907,30.606678","lon":"114.26034508395","lat":"30.612935608283","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"银联卡,信用卡支付,加油卡,便利店","distance":12511},{"id":"8892","name":"中石化五里加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区汉阳大道316号","brandname":"中石化","type":"直营店","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.254505,30.550811","lon":"114.26092817171","lat":"30.557056799261","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":9732},{"id":"47702","name":"中石化玉带门加油站","area":"430033","areaname":"湖北省 武汉市 硚口区","address":"湖北省武汉市硚口区京汉大道建国路特1号(祟仁路至桥口方向,地铁集团附近)","brandname":"中石化","type":"直营店","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.254516,30.571964","lon":"114.26093030604","lat":"30.578207291699","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡,便利店","distance":10421},{"id":"3248","name":"中石化青年路加油站","area":"430033","areaname":"湖北省 武汉市 硚口区","address":"湖北省武汉市桥口区解放大道585号,解放大道与航空路交叉","brandname":"中石化","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.256956,30.589896","lon":"114.26338833234","lat":"30.596109715243","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":11161},{"id":"3250","name":"中石化青年路加油站","area":"430033","areaname":"湖北省 武汉市 硚口区","address":"湖北省武汉市硚口区建设大道与航空路路口东200米路北","brandname":"中石化","type":"其他","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.250589627,30.5836655797","lon":"114.26354618034","lat":"30.596405592512","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"E93#":"5.7"},"fwlsmc":"加油卡","distance":11166},{"id":"52161","name":"两湖路加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区两湖路与新五里后堤交叉处,芳草苑附近","brandname":"不详","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.2582592582,30.5212424922","lon":"114.26472225948","lat":"30.527444991614","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"","distance":9330},{"id":"54720","name":"中石化白沙洲北油气合建站","area":"430061","areaname":"湖北省 武汉市 武昌区","address":"湖北省武汉市武昌区三环线白沙洲服务区内北侧","brandname":"中石化","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.2650400597,30.4729104496","lon":"114.27150951472","lat":"30.478997158986","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":11000},{"id":"8893","name":"中石化白沙洲南站","area":"430061","areaname":"湖北省 武汉市 武昌区","address":"湖北省武汉市武昌区三环线下桥处,湖场村附近","brandname":"中石化","type":"其他","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.26513,30.471974","lon":"114.27159905729","lat":"30.478058363651","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"93#":"5.7","0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡,便利店","distance":11060},{"id":"10495","name":"中石化岔马路加油站","area":"430040","areaname":"湖北省 武汉市 江汉区","address":"湖北省武汉市江汉区解放大道1632号,解放大道与青年路交叉","brandname":"中石化","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.266801,30.580653","lon":"114.27326931334","lat":"30.586705763923","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":9801},{"id":"1137","name":"中石化交通加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区鹦鹉大道与新民一街交叉口,路东","brandname":"中石化","type":"其他","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.260807775,30.5297201838","lon":"114.273748","lat":"30.541908","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"E93#":"5.7"},"fwlsmc":"加油卡","distance":8340},{"id":"47699","name":"中石油鹦鹉加油站","area":"430050","areaname":"湖北省 武汉市 汉阳区","address":"湖北省武汉市汉阳区鹦鹉大道与龟山北路一号,鹦鹉音像制品厂内","brandname":"中石油","type":"直营店","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.267544,30.555849","lon":"114.27401798863","lat":"30.561889149583","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"银联卡,信用卡支付,加?涂?,便利店,发卡充值网点,银联卡充值,加油卡充值业务","distance":8629},{"id":"303","name":"中石化石桥加油站","area":"430040","areaname":"湖北省 武汉市 江汉区","address":"湖北省武汉市江汉区路姑嫂树路和兴业路交叉口向南,路东","brandname":"中石化","type":"其他","discount":"打折加油站","exhaust":"国Ⅳ","position":"114.267576,30.624646","lon":"114.27408293469","lat":"30.630694367322","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"加油卡","distance":12979},{"id":"16573","name":"北湖西路三丰加油站 ","area":"430040","areaname":"湖北省 武汉市 江汉区","address":"湖北省武汉市江汉区北湖西路薄利通信对面","brandname":"不详","type":"其他","discount":"非打折加油站","exhaust":"国Ⅳ","position":"114.268116,30.603663","lon":"114.27461064049","lat":"30.609697747818","price":{"E90":"5.1","E93":"5.4","E97":"5.8","E0":"5.05"},"gastprice":{"0#车柴":"5.35","E93#":"5.7"},"fwlsmc":"","distance":11245}],"pageinfo":{"pnums":20,"current":"1","allpage":8}}

解析层

public class JsonDecode {
    Map <String ,Station> stationMap = new HashMap<>();
    public void init(String lineTxt)//传入的json字符串
    {
        JSONObject jObject = new JSONObject(lineTxt);
        JSONArray array = jObject.getJSONArray("data");

        for(int i = 0; i < array.length(); ++i)
        {
            Station oilInf = new Station();

            String str = array.get(i).toString();
            JSONObject json = new JSONObject(str);

            oilInf.setName(json.get("name").toString());
            oilInf.setArea(json.get("area").toString());
            oilInf.setAreaname(json.get("areaname").toString());
            oilInf.setAddress(json.get("address").toString());
            oilInf.setBrandname(json.get("brandname").toString());
            oilInf.setType(json.get("type").toString());
            oilInf.setDiscount(json.get("discount").toString());
            oilInf.setExhaust(json.get("exhaust").toString());
            oilInf.setPosition(json.get("position").toString());
            oilInf.setLon(json.get("lon").toString());
            oilInf.setLat(json.get("lat").toString());
            oilInf.setDistance(json.get("distance").toString());
            oilInf.setFwlsmc(json.get("fwlsmc").toString());

            JSONObject tJson = new JSONObject(json.get("price").toString());
            Map<String, String> price = new HashMap<>();
            price.put("E90", tJson.get("E90").toString());
            price.put("E93", tJson.get("E93").toString());
            price.put("E97", tJson.get("E97").toString());
            price.put("E0", tJson.get("E0").toString());
            oilInf.setPrice(price);
            stationMap.put(json.get("id").toString(),oilInf);

        }
    }
    public void print() {
        Iterator it = stationMap.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            System.out.println(stationMap.get(key).getName());
            Station s = stationMap.get(key);
            Map<String,String> p = s.getPrice();
            Iterator i = p.keySet().iterator();
            while (i.hasNext())
            {
                String k = i.next().toString();
                System.out.println(k + " = " + p.get(k));
            }System.out.println();
        }
    }
}

station数据结构

import java.util.Map;

public class Station{
    private String name = null;
    private String area = null;
    private String areaname = null;
    private String address = null;
    private String brandname = null;
    private String type = null;
    private String discount = null;
    private String exhaust = null;
    private String position = null;
    private String lon = null;
    private String lat = null;
    private String fwlsmc = null;
    private String distance = null;
    private Map<String, String> price = null;

    public void setDistance(String distance){
        this.distance = distance;
    }
    public String getDistance() {
        return this.distance;
    }
    public void setFwlsmc(String fwlsmc){
        this.fwlsmc = fwlsmc;
    }
    public String getFwlsmc()
    {
        return this.fwlsmc;
    }

    public void setPrice(Map<String, String> price){
        this.price = price;
    }
    public Map<String, String> getPrice(){
        return this.price;
    }

    public void setName(String name){
        this.name = name; 
    }
    public void setArea(String area){
        this.area = area;
    }
    public void setAreaname(String areaname) {
        this.areaname = areaname;
    }
    public void setAddress(String address){
        this.address = address;
    }
    public void setBrandname(String brandname){
        this.brandname = brandname;
    }
    public void setType(String type) {
        this.type = type;
    }
    public void setDiscount(String discount) {
        this.discount = discount;
    }
    public void setExhaust(String exhaust) {
        this.exhaust = exhaust;
    }
    public void setPosition(String position) {
        this.position = position; 
    }
    public void setLon(String lon) {
        this.lon = lon;
    }
    public void setLat(String lat) {
        this.lat = lat;
    }

    public String getName(){
        return this.name;
    }
    public String getArea(){
        return this.area;
    }
    public String getAreaname() {
        return this.areaname;
    }
    public String getAddress(){
        return this.address;
    }
    public String getBrandname(){
        return this.brandname;
    }
    public String getType() {
        return this.type;
    }
    public String getDiscount() {
        return this.discount;
    }
    public String getExhaust() {
        return this.exhaust;
    }
    public String getPosition() {
        return this.position;
    }
    public String getLon() {
        return this.lon;
    }
    public String getLat() {
        return this.lat;
    }
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值