失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > json 字符串和json对象之间相互转换

json 字符串和json对象之间相互转换

时间:2019-01-10 03:14:20

相关推荐

json 字符串和json对象之间相互转换

private String getBigDataRecProductIds(Map<String, Object> recRequestParams, List<String> productList,Map<String, String> productScoreMap) {String rec_batch_id = "";logger.info("获取大数据推荐http post:" + recUrl + "params:" + JSONObject.toJSON(recRequestParams));LogUtils.startLogWeb("请求智能推荐城市热销");String result = HttpUtils.post(recUrl, recRequestParams, 1000);LogUtils.endLogWeb();logger.info("获取大数据推荐http post:" + recUrl + "result:" + result);JSONObject jsonObject = JSONObject.parseObject(result);if (jsonObject == null) {return null;}if (jsonObject.get("rec_batch_id") != null) {rec_batch_id = jsonObject.get("rec_batch_id").toString();if (jsonObject.get("rec_list") != null) {JSONArray jsonArray = (JSONArray) jsonObject.get("rec_list");Iterator<Object> iterator = jsonArray.iterator();while (iterator.hasNext()) {Map<String, Object> recMap = (Map<String, Object>) iterator.next();if (recMap.get("product_id") != null && recMap.get("category_id") != null && recMap.get("rec_score") != null) {String productId = recMap.get("product_id").toString();String categoryId = recMap.get("category_id").toString();String productScore = recMap.get("rec_score").toString();productList.add(productId);productScoreMap.put(productId + "_" + categoryId, productScore);}}}} else {logger.warn("cityHotsaleRec warn未获取到推荐数据 params:" + JSONObject.toJSON(recRequestParams));if (jsonObject.get("errorMessage") != null) {LogUtils.appendLogWeb("大数据未获取推荐 cause:" + jsonObject.get("errorMessage").toString());}}return rec_batch_id;}

如果觉得《json 字符串和json对象之间相互转换》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。