1. 程式人生 > >處理http請求返回的json串

處理http請求返回的json串

       "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");

                                        }