1、Json数组
[
{
"post":"",
"name":"张超",
"phone":"010-62987632",
"email":"",
"qq":"",
"postcode":null,
"telephone":null,
"fax":null,
"purchaseUsers":null
},
{
"post":"",
"name":"褚利",
"phone":"13811077290",
"email":"",
"qq":"",
"postcode":null,
"telephone":null,
"fax":null,
"purchaseUsers":null
}
]
对于上图中的json数组,可以JSON.parseArray(contact)解析
JSONArray jsonArray = JSON.parseArray(contact);
if (Objects.nonNull(jsonArray)) {
JSONObject jsonObject = jsonArray.getJSONObject(0);
providerInfoAResp.setEmail(jsonObject.getString(EMAIL));
providerInfoAResp.setCompanyTel(jsonObject.getString(PHONE));
}
2、对redis中json数据的处理
ResponseData responseData = new ResponseData();
String key = RemoteService4SccSrmBasicserviceServiceConstant.APP_ID + ":" + providerCode + ":" + CoreDataService.CORE_DATA_YEAR_REDIS;
Object coreData = redisCacheService.get(key);
if(ObjectUtils.isEmpty(coreData)){
responseData.setData(coreDataService.getCoreDataInfoByYear(providerCode));
}else{
JSONObject jsonObject= JSON.parseObject(coreData.toString());
CoreDataInfoAResp coreDataInfoAResp = JSON.toJavaObject(jsonObject, CoreDataInfoAResp.class);
responseData.setData(coreDataInfoAResp);
}
|