gpt4 book ai didi

ios - 如何实现 SwiftyJSON 来获取这些数据

转载 作者:行者123 更新时间:2023-11-28 15:25:24 24 4
gpt4 key购买 nike

我一直在接触 Swift,我发现 SwiftyJSON 是一个很好的解析 JSON 的库,但仍然不知道如何正确使用它。我需要使用 SwiftyJSON 从这个 JSON 中获取每个用户的 id 值并将它们保存到一个数组中:

    {
"users": [
{
"id": 2960784075,
"id_str": "2960784075",
"name": "Jesus Rafael Abreu M",
"screen_name": "chuomaraver",
"location": "",
"profile_location": null,
"url": null,
"description": "",
"protected": false,
"followers_count": 1,
"friends_count": 101,
"listed_count": 0,
"created_at": "Sun Jan 04 19:58:06 +0000 2015",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 0,
"lang": "es",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"default_profile": true,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"muting": false
},
{
"id": 2959453074,
"id_str": "2959453074",
"name": "lama masarwa",
"screen_name": "LamaMasarwa",
"location": "",
"profile_location": null,
"url": null,
"description": "",
"protected": false,
"followers_count": 7,
"friends_count": 53,
"listed_count": 0,
"created_at": "Mon Jan 05 10:10:46 +0000 2015",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "he",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/552047388873859072/itk5cPx6_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/552047388873859072/itk5cPx6_normal.png",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/2959453074/1420454122",
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"default_profile": true,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"muting": false
},...

有人可以帮助我了解我该怎么做吗?非常感谢!

最佳答案

你可以这样解析json。

var IDs: [String] = []

//json is object where users are available
let users = json["users"].arrayValue

users.forEach( {
IDs.append($0["id"].stringValue)
})

print(IDs)

关于ios - 如何实现 SwiftyJSON 来获取这些数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45326450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com