我使用this API获得用户的关注者列表中的用户的完整信息,并作为文档中的描述返回JSON格式的追随者。这里是一个返回对象的一个片段:获取使用TwitterKit
{
"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",
.....
.....
"default_profile": true,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"muting": false
},
.....
.....
],
"next_cursor": 1489467234237774933,
"next_cursor_str": "1489467234237774933",
"previous_cursor": 0,
"previous_cursor_str": "0"
}
你可能注意到了,用户对象有很多的属性,我不想 分析逐一或使用一个库做的我。
的TwitterKit有一个名为TWTRUser类,这里是它的documentation。要初始化这个类的一个对象,你可以只使用一个构造函数一个JSON字典是这样的:
let follower = TWTRUser(jsonDictionary: jsonDictionary)
这样我可以得到JSON对象返回到我的分析和初始化TWTRUser
对象。
的问题是,TWTRUser
没有列在JSON返回的所有属性,它只有作为documentation列出的这些属性:
UserID属性
name属性
屏幕名财产
isVerified 财产
isProtected财产
profileImageURL财产
profileImageMiniURL财产
profileImageLargeURL财产
formattedScreenName财产
profileURL财产
我试图用valueForKey方法,它采用一键,返回它的价值是这样的:
let createdAt = follower.value(forKey: "created_at")
我认为这会工作,但事实并非如此。当我使用它的应用程序崩溃,并给了我下面的消息:
终止应用程序由于未捕获的异常“NSUnknownKeyException”, 原因:“[valueForUndefinedKey:]:此类 不是键值编码兼容的主要贡献者启用。“
我能做的使用TWTRUser
类来获取用户的所有属性?
显示你的代码? –
你在哪里使用'contributors_enabled' –
@AhhhhhhJJain我提到我试图使用'TWTRUser'的* valueForKey *方法,并且我还说我可以以本地方式解析JSON或使用库,但我是寻找另一种解决方案。 –