gpt4 book ai didi

objective-c - 如何从 NSArray 获取元素

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:08 27 4
gpt4 key购买 nike

我有一个从 Twitter REST API 的 json 数据构建的 NSArray。

NSArray *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];

NSLog (@"Element %@", [dict objectAtIndex: 1]);

如何从数组中获取单个元素,其中一个数组索引项如下所示:

Element 1 = {
contributors = "<null>";
coordinates = "<null>";
"created_at" = "Tue Feb 07 11:15:08 +0000 2012";
entities = {
hashtags = (
);
urls = (
);
"user_mentions" = (
);
};
favorited = 0;
geo = "<null>";
id = 166842424398848000;
"id_str" = 166842424398848000;
"in_reply_to_screen_name" = "<null>";
"in_reply_to_status_id" = "<null>";
"in_reply_to_status_id_str" = "<null>";
"in_reply_to_user_id" = "<null>";
"in_reply_to_user_id_str" = "<null>";
place = "<null>";
"retweet_count" = 0;
retweeted = 0;
source = web;
text = "another day is here so ready to be off from work already...";
....

最佳答案

你可以试试,

NSString *string = [[dict objectAtIndex: 1] objectForKey:@"keyName"];

如果我没看错的话,你的数据中有一个子字典(“entities”)

NSDictionary *entitiesDict = [[dict objectAtIndex: 1] objectForKey:@"entities"];

如前所述使用 NSDictionary :)

关于objective-c - 如何从 NSArray 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9175466/

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