1、json示例
{ "pageSize":20, // 每页显示多少 "toPage":1, // 当前页码 "totalCount":1, // 一共多少条 "totalPages":1, // 一共多少页 "success":true, "errorCode":null, "other":null, "msgCode":null, "msgInfo":null, "messages":[], "result":[{ "id":12362, //关键字ID "keyword":"杭州 交通事故", //关键字内容 "topicId":6544, //关键字专题ID "createdAt":"2016-04-28T03:09:12.000Z", "updatedAt":"2016-04-28T03:09:12.000Z", "spiderTopics":[{ "id":2252, //站点组ID,用于舆情搜索时,指定的spiderTopicId "name":"新闻" //站点组名称 },{ "id":2253, "name":"微博" }] }] } 2、Java代码 JSONObject json = JSONObject.parseObject("待解析的json字符串"); System.out.println(JSONObject.toJSONString(json, true)); JSONArray array = json.getJSONArray("result"); List<Keyword> keywords = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject jo = array.getJSONObject(i); assertEquals(topic.getId(), jo.getInteger("topicId")); keywords.add(new Keyword(topic, jo.getInteger("id"), jo.getString("keyword"), null, jo.getJSONArray("spiderTopics"), jo.getString("updatedAt"), jo.getString("createdAt"))); }