FastJson对于JSON格式字符串、JSON对象及JavaBean之间的相互转换
一.result格式:
{
"success":"true";
"code":"1"
}
获取内容
JSONObject jsonObject = JSON.parse(result);
jsonObject.getString("code") ; //获取object中code字段;
二.result格式:
{
"success":"true";
"data":{
"name":"FF",
"id":"77"
};
}
获取结果:
JSONObject name= JSON.parseObject(result);
JSON.parseObject(name.getString("data").getString("name"))
三.result格式:
{ "success":"true";
"data":[
{"shop_uid":"123";},
{"shop_name":"张三"}
]
}
JSONArrary detail = JSON.parseArr(resulr);
for (int i=0;i<detail.size();i++){
if(detail.get(i)!=null || !detail.get(i).equal(" ")){
JSONArray detailChild = detail.getJSONArray(i);
if(detailChild.getInteger(1)>Integer.ValueOf(ship.get("shiptime").toString())){
ship.put("shiptime",detailChild.getInteger(1));
ship.put("desc",detailChild.getString(0));
}
}
}
JSON转javaBean
JSONObject contentChild = contentsArray.getJSONObject(i);
QCCustomerScore.CustomerCore customerCore = JSON.toJavaObject(contentChild, QCCustomerScore.CustomerCore.class);