1、json格式如下:要取其中的fileUrl字段的值

{
    "msg": "请求成功",
    "code": "200",
    "data": {
        "total": 11,
        "code": 200,
        "list": [
            {
                "leagueDetails": "[{\"status\":\"success\",\"name\":\"3.jpg\",\"size\":14190,\"percentage\":100,\"uid\":1567393378927,\"raw\":{\"uid\":1567393378927},\"response\":{\"code\":200,\"data\":{\"fileName\":\"3.jpg.jpg\",\"fileUrl\":\"https://intelligentclasspic.whochange.com/class1567393508500.jpg\"},\"message\":\"OK\"}},{\"status\":\"success\",\"name\":\"u=175171,1958553578&fm=26&gp=0.jpg\",\"size\":35959,\"percentage\":100,\"uid\":1567413590310,\"raw\":{\"uid\":1567413590310},\"response\":{\"code\":200,\"data\":{\"fileName\":\"u=175171,1958553578&fm=26&gp=0.jpg.jpg\",\"fileUrl\":\"https://intelligentclasspic.whochange.com/class1567413545721.jpg\"},\"message\":\"OK\"}},{\"status\":\"success\",\"name\":\"u=41048870,3454661097&fm=15&gp=0.jpg\",\"size\":31793,\"percentage\":100,\"uid\":1567413595292,\"raw\":{\"uid\":1567413595292},\"response\":{\"code\":200,\"data\":{\"fileName\":\"u=41048870,3454661097&fm=15&gp=0.jpg.jpg\",\"fileUrl\":\"https://intelligentclasspic.whochange.com/class1567413550675.jpg\"},\"message\":\"OK\"}}]",
               ]
            },
        "message": "OK",
        "updateTotal": "0"
    }
}

2、用JSONObject解析的代码如下:

HashMap<String, Object> allList = new HashMap<String, Object>();
allList = openPlatFeignClient.open(parameterUtil);
				JSONObject dataJson = new JSONObject(allList); //获取了上面例子的json
				String code = dataJson.get("code").toString();
				if ("200".equals(code)) {
						JSONArray leagueDetails = info.getJSONArray("leagueDetails");
						if (leagueDetails != null) {
							String images = "";
							String temp = "";
							for (int j = 0; j < leagueDetails.size(); j++) {
								JSONObject info3 = leagueDetails.getJSONObject(j);
								JSONObject response = info3.getJSONObject("response");
								JSONObject data = response.getJSONObject("data");
								temp = "{\"file\":\"" + data.getString("fileUrl") + "\"},";
								images = temp + images;
							}
							images = images.substring(0, images.length() - 1); 				 
                }

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐