【问题标题】:How to get JSONObject without JSONArray如何在没有 JSONArray 的情况下获取 JSONObject
【发布时间】:2020-03-27 16:41:08
【问题描述】:

我有这样一个 JSON:https://paste.ubuntu.com/p/HkTK9xTzNx/

如何获得“imdb_id”字符串(第 14 行)。没有包含该值的数组,它不在方形分支中,所以我不知道如何获取它。

【问题讨论】:

  • 所有json文件都转换成JsonObject,例如name parent,必须从这个数组中获取imdb_id。

标签: android json android-studio


【解决方案1】:

根据您的需要解决方案:

try {
     imdbLink = response.getString("imdb_id");
 } catch (JSONException e) {
      e.printStackTrace();
 }

标准解决方案:

String json = "{\"imdb_id\":\"str12345\"}"; // your json response from network call/local file

JSONObject jsonObject;

try {
    jsonObject = new JSONObject(json);

    String id = jsonObject.getString("imdb_id");

} catch (Exception e) {
     e.printStackTrace();
}

【讨论】:

猜你喜欢
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-20
  • 1970-01-01
相关资源
最近更新 更多