【问题标题】:How to read json response using jsonArray in java code如何在 java 代码中使用 jsonArray 读取 json 响应
【发布时间】:2017-03-23 04:59:00
【问题描述】:

我有一个查询,我必须从下面提到的 json 响应中读取 key“studentData”下的 key“class”。 {

“学生数据”:[ { “姓名”:“约翰”, “类”:2, “rollno”:“2015” } ], “入学年份”:2017 }

请帮忙。

提前致谢

【问题讨论】:

    标签: arrays json httpclient


    【解决方案1】:
    JSONObject jsonObjectResponse = new JSONObject(response.toString()); //obtain the object
    JSONArray jsonMainNode = jsonObjectResponse.optJSONArray("studentData");//get array from object
    JSONObject jsonChildNode = jsonMainNode.getJSONObject(0);//get first object in array
    String studentDataValue = jsonChildNode.optString("class");//obtain value from class key
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-03
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 2019-08-09
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多