fastjson 从jsonArray中获取、遍历jsonObject属性

1.json字符串转jsonArray

JSONArray json  = JSONArray.parseArray(json_String);
2.jsonArray到jsonObject的转换

  for (int i = 0; i < jsonArray.size(); i++)
            {
                row = sheet.createRow(num++);
                JSONObject object = (JSONObject) jsonArray.get(i);
             
                object.getString('属性');
 
                }

 

 JSONArray query_rewrite_list = response.getJSONArray("query_rewrite");

                StringBuffer sb_query = new StringBuffer();
                StringBuffer sb_score = new StringBuffer();
                String tagging分词query = "";
                String tagging分词score = "";

                // 遍历JSONArray下的JSONObject,以及String类型的value值
                for (int i = 0; i < query_rewrite_list.size(); i++) {
                    String query_rewrite_extention = response.getJSONArray("query_rewrite").
                            getJSONObject(i).getString("extention");

                    String query_rewrite_level = response.getJSONArray("query_rewrite").
                            getJSONObject(i).getString("level");

                    System.out.println("第" + (i + 1) + "个getJSONObject的extention为" + query_rewrite_extention);
                    System.out.println("第" + (i + 1) + "个getJSONObject的level为" + query_rewrite_level);


                    tagging分词query = sb_query.append(query_rewrite_extention + ",").toString();

                    tagging分词score = sb_score.append(query_rewrite_level + ",").toString();

                    // 单个字段写入-原始query 纠错词qc 类型-第一个卡片的主标题
//                    FileWrite.queryTagging("第" + (i + 1) + "个==" + query + "   " + query_rewrite_n);

                }

                // JSONArray下获取所有的JSONObject里的extention,按","拆分打印为一行。StringBuffer可缓存字符串拼接
                System.out.println("分词数组为" + tagging分词query);
                // 结果写入queryTagging_log.txt文件
                FileWrite.queryTagging(query + tagging分词query);
                FileWrite.queryTagging("======================");
                FileWrite.queryTagging(query + tagging分词score);

 

3.jsonObject到jsonArray的转换

 JSONArray seconddataArray = object.getJSONArray("jsonArray的key");
                    for (int x = 0; x < seconddataArray.size(); x++)
                    {
                       
                        JSONObject seconddata = (JSONObject) seconddataArray.get(x);}

 

你可能感兴趣的:(code)