json数组解析

 1 private String collectDataJson(String dataListJson){
 2 
 3         String topic = HBPHelper.getTopic(HBPCollectorConstant.PIPELINE_INFO, 1);
 4 
 5         JSONObject resObj = JSON.parseObject(dataListJson);
 6         if (false==resObj.containsKey("data")) {
 7             return "参数不符合规范";
 8         }
 9         Object data = resObj.get("data");
10         if (data instanceof JSONArray) {
11             JSONArray jsonArray = (JSONArray) data;
12             LOG.info("start to collect data,data num is [{}]", jsonArray.size());
13             for (int i=0;i<jsonArray.size();i++) {
14                 String jsonString = jsonArray.getString(i);
15                 if (jsonString.length() < PB_LENGTH) {
16                     return "pb数据长度应大于" + PB_LENGTH;
17                 }
18                 byte[] jsonByte = HBPHelper.decode(jsonString);
19                 KafkaUtil.getINSTANCE().getByteProducer(topic).send(jsonByte);
20             }
21         }
22         return "OK";
23     }

 

posted on 2017-02-14 14:30  聂政didi  阅读(420)  评论(0编辑  收藏  举报

导航