需要格式如下
[
{
key:"aaa",
name:"bbbb"
},
{
key:"aaa1",
name:"bbb2"
},
....
]
但是接口返回格式如下
{"code":0,
"data":"{\"xxx1\":\"日期1\",\"xxx2\":\"时段1\",\"xxx3\":\"x角色2\",
\"xxx4\":\"新增角色\",\"xxx5\":\"充值RMB\",\"xxx6\":\"充值次数\",\"xxx7\":\"充值角色\",
\"xxx8\":\"新增付费角色数\",\"xxx9\":\"角色留存数\",\"xxx10\":\"活跃ARPU\"}",
"encrypt":false,
"msg":"ok",
"success":true
}
接下来看java 如何转化
List<Map<String, Object>> resultData = new ArrayList<>();
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(url);
int status = httpClient.executeMethod(getMethod);
if(status == 200){
String body = getMethod.getResponseBodyAsString();
JSONObject jsonObject = JsonUtil.JSONStrToJSONObject(body) ;
JSONObject tmpData = jsonObject.getJSONObject("data") ; //拿到data数据
if(tmpData!=null && tmpData.size()>0 ){
for (String key : tmpData.keySet()) {
HashMap<String, Object> tmpMap = new HashMap<String, Object>() {
{
put("key", key);
put("name", tmpData.get(key));
}
};
resultData.add(tmpMap) ;
}
}
system.out.printIn(resultData);//这就是你想要的数据了
return "xxxxx";
}else{
return "xxxxx";
}