JSON串解析

{
  "conclusion": "不合规",
  "log_id": 16087134146452295,
  "data": [
    {
      "msg": "存在百度官方默认违禁词库不合规",
      "conclusion": "不合规",
      "hits": [{
        "datasetName": "百度默认黑词库",
        "words": ["*"]
      }],
      "subType": 0,
      "conclusionType": 2,
      "type": 11
    },
    {
      "msg": "存在*不合规",
      "conclusion": "不合规",
      "hits": [{
        "probability": 1,
        "datasetName": "百度默认文本反作弊库",
        "words": ["*"]
      }],
      "subType": 3,
      "conclusionType": 2,
      "type": 12
    },
    {
      "msg": "存在低俗辱骂不合规",
      "conclusion": "不合规",
      "hits": [{
        "probability": 1,
        "datasetName": "百度默认文本反作弊库",
        "words": ["尼玛"]
      }],
      "subType": 5,
      "conclusionType": 2,
      "type": 12
    }
  ],
  "conclusionType": 2
}
JSONArray dataArray = res.getJSONArray("data");
            System.out.println(dataArray.toString(2));
            // 对data中进行解析
            /*
             * 为什么选用hashset容器:
             * 因为自动去除重复
             * */
            HashSet<String> hashSet=new HashSet<>();
            for(int i=0;i<dataArray.length();i++){

                JSONObject object=dataArray.getJSONObject(i);

                JSONArray hitsArray=object.getJSONArray("hits");

                System.out.println(hitsArray);

                JSONObject hitsJSON=hitsArray.getJSONObject(0);
                System.out.println("xxx"+hitsJSON);

                JSONArray wordsArray = hitsJSON.getJSONArray("words");
                System.out.println((wordsArray.toString()).substring(2,(wordsArray.toString()).length() - 2));

                hashSet.add((wordsArray.toString()).substring(2,(wordsArray.toString()).length() - 2));

                System.out.println(hashSet.toString());

            }

 

上一篇:继承《JavaScript高级程序设计》


下一篇:JavaScript深入理解之继承