使用swiftyJson解析JSON对象

时间:2017-06-28 15:25:54

标签: swift swifty-json

我在API调用中有以下JSON响应(见下文)。我试图检索用户ID并将其存储在一个数组中,但我似乎无法隔离用户ID。

这样做的理想方式是什么。

{
    "status": "ok",
    "followers": {
        "3": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com"
        },
        "31": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "35": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "37": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "43": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com"
        },
        "47": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "64": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "202": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "357": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "387": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "2328": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "2333": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "2334": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        },
        "2371": {
            "username": "username",
            "display_name": "username",
            "mail": "username@domain.com
        }
    },
    "count": 14
}

我可以将状态和计数值检索为字符串和整数值,但是很难将id号分开,在本例中为[3,31,35,37,43,47,64,202,357,387,2328,2333,2334,2371]

let status = json["status"].stringValue
let count = json["count"].intValue

0 个答案:

没有答案