【问题标题】:How to parse my JSON String in Android? [duplicate]如何在 Android 中解析我的 JSON 字符串? [复制]
【发布时间】:2017-05-03 09:03:08
【问题描述】:

[{"id":"1","name":"Nurullah","surname":"xxxxxx","il":"eskisehir"},{"id":"2","name" :"Ozgur","surname":"yyyyyy","il":"istanbul"},{"id":"3","name":"Emre","surname":"zzzzzz","il" :"安卡拉"}]

我在上面展示了我的 JSON。我不知道如何在 android 中解析我的字符串?谢谢你的回答。

【问题讨论】:

  • 在此处发布问题之前请先谷歌。
  • 你到现在都做了什么?
  • @Denny 请不要将此帖子用作参考。它仍然存在是有历史原因的,否则它就不会存在了。
  • 我在谷歌上找过,但我不明白他们的 json 格式不同。 @chintan-soni
  • @greenhoorn 我认为您误解了横幅说明。虽然我们不再需要要求分步说明、指南或教程的问题,但答案中的信息仍然完全有效,可以用作参考。

标签: android json parsing


【解决方案1】:

基本上 '[]' 这表示为 JSONArray 和 '{}' 这表示 JSONObject

 try {
        JSONArray jsonArray = new JSONArray(response);
        for(int i=0; i<jsonArray.length(); i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);

            String id = jsonObject.getString("id");
            String name = jsonObject.getString("name");
            String surname = jsonObject.getString("surname");
            String il = jsonObject.getString("il");
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

【讨论】:

猜你喜欢
  • 2011-12-26
  • 2016-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多