如何阅读长http响应体

时间:2015-07-09 09:32:25

标签: android json

我用 Android中的HttpURLConnection Github API用于读取我的github帐户的事件。我使用的http库是Volley。

我请求的网址是https://api.github.com/users/Leaking/received_events/public

响应是一个json数组。当这个json数组的长度足够长(可能大于10)时,我输入读取所有json数组并且只读取部分json数组字符串。如下所示

我想知道回复正文是否太长而无法阅读。

[
{
    "id": "2958450223",
    "type": "WatchEvent",
    "actor": {
        "id": 1114542,
        "login": "nvbn",
        "gravatar_id": "",
        "url": "https://api.github.com/users/nvbn",
        "avatar_url": "https://avatars.githubusercontent.com/u/1114542?"
    },
    "repo": {
        "id": 6817270,
        "name": "fsantanna/ceu",
        "url": "https://api.github.com/repos/fsantanna/ceu"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T21:26:51Z"
},
{
    "id": "2956734206",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 23112526,
        "name": "android10/Android-CleanArchitecture",
        "url": "https://api.github.com/repos/android10/Android-CleanArchitecture"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:12:49Z"
},
{
    "id": "2956726542",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 38324286,
        "name": "cooltechworks/BitmapMerger",
        "url": "https://api.github.com/repos/cooltechworks/BitmapMerger"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:10:20Z"
},
{
    "id": "2956721687",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 37834277,
        "name": "openstf/stf",
        "url": "https://api.github.com/repos/openstf/stf"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:08:46Z",
    "org": {
        "id": 12196621,
        "login": "openstf",
        "gravatar_id": "",
        "url": "https://api.github.com/orgs/openstf",
        "avatar_url": "https://avatars.githubusercontent.com/u/12196621?"
    }
},
{
    "id": "2956719107",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 14712620,
        "name": "CyberAgent/adbkit",
        "url": "https://api.github.com/repos/CyberAgent/adbkit"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:07:58Z",
    "org": {
        "id": 865695,
        "login": "CyberAgent",
        "gravatar_id": "",
        "url": "https://api.github.com/orgs/CyberAgent",
        "avatar_url": "https://avatars.githubusercontent.com/u/865695?"
    }
},
{
    "id": "2956716059",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 4397781,
        "name": "wsieroci/audiorecognizer",
        "url": "https://api.github.com/repos/wsieroci/audiorecognizer"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:06:55Z"
},
{
    "id": "2956704073",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 3586085,
        "name": "SimonVT/android-numberpicker",
        "url": "https://api.github.com/repos/SimonVT/android-numberpicker"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:02:44Z"
},
{
    "id": "2956697058",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Trinea",
        "avatar_url": "https://avatars.githubusercontent.com/u/1169522?"
    },
    "repo": {
        "id": 36551310,
        "name": "tittojose/TimeRangePicker",
        "url": "https://api.github.com/repos/tittojose/TimeRangePicker"
    },
    "payload": {
        "action": "started"
    },
    "public": true,
    "created_at": "2015-07-08T13:00:20Z"
},
{
    "id": "2956696712",
    "type": "WatchEvent",
    "actor": {
        "id": 1169522,
        "login": "Trinea",
        "gravatar_id": "",
        "url": "https://api.github.com/us!!!!!I just read half of it.

1 个答案:

答案 0 :(得分:0)

我用postman app来读取服务器的响应。在谷歌浏览器中,您可以在Chrome Postman - REST Client shortcut

找到它

这些工具对于帮助您在使用API​​时提高效率非常有用。

它可以为JSON和XML提供格式化的API响应。

希望有所帮助。