1

下面的代码是我的 JSON 文件,我想从服务器读取这些数据,那么如何在 andorid 中使用 JSONObject 读取这些数据

此代码包含以自身开头的数组标识符,没有数组的名称标识符


[
    {
        "created_at": "Sat Nov 10 12:00:26 +0000 2012",
        "id": 267235264374640640,
        "id_str": "267235264374640640",
        "text": "My text",
        "user": {
            "id": 166551306,
            "id_str": "166551306",
            "name": "John ",
            "location": "Chennai, India",
            "url": null,
            "notifications": null
          },
        "geo": null,
        "coordinates": null,
        "place": null,
        "contributors": null,
        "retweet_count": 0,
        "entities": {
            "hashtags": [],
            "urls": [],
            "user_mentions": []
        },
        "favorited": false,
        "retweeted": false
    },
   {
        "created_at": "Sat Nov 10 12:00:26 +0000 2012",
        "id": 267235264374640640,
        "id_str": "267235264374640640",
        "text": "My text",
        "user": {
            "id": 166551306,
            "id_str": "166551306",
            "name": "John ",
            "location": "Chennai, India",
            "url": null,
            "notifications": null
          },
        "geo": null,
        "coordinates": null,
        "place": null,
        "contributors": null,
        "retweet_count": 0,
        "entities": {
            "hashtags": [],
            "urls": [],
            "user_mentions": []
        },
        "favorited": false,
        "retweeted": false
    },
]
4

1 回答 1

1

您可以将其直接读入JSONArray 而不是JSONObject

JSONArray jsonArray = new JSONArray(dataString);

我已经使用您提供的 JSON 数据进行了尝试,并且效果很好。

于 2012-11-11T17:12:24.867 回答