如何获取JSONObject嵌套值

时间:2018-05-01 23:21:40

标签: java json

我可以知道如何获得contour_chin->x的价值吗? JSON输出如下:

{
    "image_id": "Dd2xUw9S/7yjr0oDHHSL/Q==",
    "request_id": "1470472868,dacf2ff1-ea45-4842-9c07-6e8418cea78b",
    "time_used": 752,
    "faces": [{
        "landmark": {
            "mouth_upper_lip_left_contour2": {
                "y": 185,
                "x": 146
            },
            "contour_chin": {
                "y": 231,
                "x": 137
            },
  //   .............landmarks omitted...........
            "right_eye_pupil": {
                "y": 146,
                "x": 205
            },
            "mouth_upper_lip_bottom": {
                "y": 195,
                "x": 159
            }
        }
    }]
}

我尝试过的代码是:

JSONObject jObj = new JSONObject(response.body().string());
JSONArray jArr = jObj.getJSONArray("faces");
JSONObject jObj3 = (JSONObject) jArr.get(0);
JSONObject jObj4 = jObj3.getJSONObject("contour_chin");
String result = jObj4.getString("x");
return result;

输出错误没有值为contour_chin。我可以知道怎么做吗?

1 个答案:

答案 0 :(得分:0)

看起来你需要:

.sample {
  width:300px;
  height:150px;
  background-color: red;
  border-radius:20px;
  border: solid 15px green;
  border-top-color: blue;
  border-left-color: blue;
}