fastJson解析复杂的json字符串,经测试已经成功解析

要解析的json数据格式为:

HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
    ResponseStatus: 
    {
        
    },
    Data: 
    {
        TourCopyWriterInfo: 
        {
            DefaultCopyWriter: String,
            SearchValue: String
        },
        ThemeList: 
        [
            {
                Key: String,
                Value: String,
                PoiId: String,
                IsJump: False
            }
        ],
        DestinationList: 
        [
            {
                DestName: String,
                CategoryId: 0,
                SubDestList: 
                [
                    {
                        Key: String,
                        Value: String,
                        PoiId: String,
                        IsJump: False
                    }
                ]
            }
        ],
        TourProductList: 
        {
            
        }
    }
}

要解析的为Data对象中的ThemeList数组,自己写的ThemeList元素的javabean代码如下:
/**
* Created by sqhan on 2016/5/30.
*/
public class TopTripType {
String key;
String value;
String poiId;
boolean isJump;

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getPoiId() {
return poiId;
}

public void setPoiId(String poiId) {
this.poiId = poiId;
}

public boolean isJump() {
return isJump;
}

public void setJump(boolean jump) {
isJump = jump;
}
}

解析的代码为:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//用fastjson来解析拉取到的数据,经测试已解析成功
     public List<TopTripType> parseResponseData(String responseStr) {
         List<TopTripType> result;
         try {
             JSONObject object = JSON.parseObject(responseStr);
             JSONObject data = (JSONObject) object.get( "Data" );
             JSONArray jsonArray = data.getJSONArray( "ThemeList" );
             result = JSON.parseArray(jsonArray.toJSONString(), TopTripType. class );
 
         } catch (Exception e) {
             result = new ArrayList<>();
             LogUtil.e(TAG, "parseResponseData()中解析json出现异常" );
         }
         return result;
 
     }

  OK,有些细节不再详细说明,需要请留言多多交流。



转载于:https://www.cnblogs.com/jpfss/p/9685049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值