处理http请求返回的json串

处理http返回的json串:

HttpManager httpManager = new HttpManager();
httpManager.sendHttpGetRequest(httpclient, operationUrl,
operationName);
HttpGet httpGet = new HttpGet(operationUrl);
httpGet.addHeader("Content-Type"
       "application/json;charset=UTF-8");
   org.apache.http.client.ResponseHandler handler = new BasicResponseHandler();
    String rsp = (String) httpclient.execute(httpGet, handler);
                                        JsonParser jsonParser = new JsonParser();

                                        JsonObject jsonObject = (JsonObject) jsonParser.parse(rsp);
                                        JsonObject resObj = jsonObject.get("resObj")
                                                        .getAsJsonObject();
                                        JsonArray nodeList = resObj.get("alarms").getAsJsonArray();

                                        for (int i = 0; i < nodeList.size(); i++) {

                                                JsonObject subJsonObject = nodeList.get(i)
                                                                .getAsJsonObject();
                                                Hdalm hdalm = new Hdalm(dbname, instName, check_time);
                                                hdalm.fillData(subJsonObject);

                                                socketClient.sendMsg(httpIP, httpPort, hdalm.toString()
                                                                + "\r\n");

                                        }

发布了55 篇原创文章 · 获赞 8 · 访问量 3万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览