一、标签计算
数据
86913510 {"reviewPics":[],"extInfoList":null,"expenseList":null,"reviewIndexes":[1,2],"scoreList":[{"score":5,"title":"环境","desc":""},{"score":5,"title":"服务","desc":""},{"score":5,"title":"口味","desc":""}]}
86913510 {"reviewPics":null,"extInfoList":[{"title":"contentTags","values":["午餐","分量适中"],"desc":"","defineType":0},{"title":"tagIds","values":["684","240"],"desc":"","defineType":0}],"expenseList":null,"reviewIndexes":[2],"scoreList":null}
77287793 {"reviewPics":null,"extInfoList":null,"expenseList":null,"reviewIndexes":[1,2],"scoreList":null}
77287793 {"reviewPics":null,"extInfoList":[{"title":"contentTags","values":["干净卫生","服务热情"],"desc":"","defineType":0},{"title":"tagIds","values":["852","22"],"desc":"","defineType":0}],"expenseList":null,"reviewIndexes":[1,2],"scoreList":null}
处理过程分析
(1)第一步:筛选出extInfoList不为空的记录,并去除values中的标签值
获取到的记录形式
86913510 午餐,分量适中
77287793 干净卫生,服务热情
(2)第二步:分离标签
获取到的记录形式
86913510 午餐,1
86913510 午餐,1
86913510 分量适中,1
77287793 干净卫生,1
77287793 服务热情,1
(3)第三步:统计标签
获取到的记录形式
JSON解析代码
public class JsonParse {
public static String parseTag(String json) {
JSONObject jsonObject = JSONObject.parseObject(json);
JSONArray extInfoList = jsonObject.getJSONArray("extInfoList");
if (extInfoList == null) {
return "";
}
for (Object obj : extInfoList) {
JSONObject jsonObject1 = (JSONObject) obj;
if (jsonObject1.getString("title").equals("contentTags")) {
String array2 = jsonObject1.getString("values");
return array2.replace("[", "").replace