【问题标题】:How to get nested JSON object如何获取嵌套的 JSON 对象
【发布时间】:2017-04-27 04:21:25
【问题描述】:

我正在尝试使用改造来获取嵌套的 json 对象。这是我的 json 结果

 {
  "results":
  {
    "sunrise":"7:27:02 AM",
    "sunset":"5:05:55 PM",
    "solar_noon":"12:16:28 PM",
    "day_length":"9:38:53",
    "civil_twilight_begin":"6:58:14 AM",
    "civil_twilight_end":"5:34:43 PM",
    "nautical_twilight_begin":"6:25:47 AM",
    "nautical_twilight_end":"6:07:10 PM",
    "astronomical_twilight_begin":"5:54:14 AM",
    "astronomical_twilight_end":"6:38:43 PM"
  },
   "status":"OK"
}

但我不需要所有字段,只需要日出字段。我如何在没有其他字段的情况下获得日出字段。

【问题讨论】:

标签: android gson retrofit


【解决方案1】:
JSONObject object = new JSONObject((String) o);
String sunrise = object.getJSONObject("results").getString("sunrise");

使用这个。希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-12-01
    相关资源
    最近更新 更多