gpt4 book ai didi

ios - 解析字典的问题

转载 作者:行者123 更新时间:2023-11-29 12:46:44 25 4
gpt4 key购买 nike

下面是我通过检索我的推特状态以获取仅应用程序推特提要而创建的字典。我已经成功解析并返回了“text”的值,并将其显示在表格 View 单元格中,如下所示:

static NSString *cellID =  @"FeedCell3" ;

FeedCell3 *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil) {
cell = [[FeedCell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}

NSInteger idx = indexPath.row;
NSDictionary *t = self.twitterDataSource[idx];
cell.updateLabel.text = t[@"text"];
return cell;

但是,当我尝试使用下面的方法返回“profile_image_url”和“screen_name”等键的其他值时,返回一个 (null),即使字典中有一个值。我做错了什么?

cell.nameLabel.text = t[@"screen_name"];
NSURL *profileImageURL = t[@"profile_image_url"];
NSLog(@"%@", profileImageURL);

字典数据:

contributors = "<null>";
coordinates = "<null>";
"created_at" = "Thu May 01 20:15:32 +0000 2014";
entities = {
hashtags = (
);
symbols = (
);
urls = (
);
"user_mentions" = (
);
};
"favorite_count" = 0;
favorited = 0;
geo = "<null>";
id = 461962182734217473;
"id_str" = 46398745473;
"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>";
lang = fr;
place = "<null>";
"retweet_count" = 0;
retweeted = 0;
source = web;
text = "Test Tweet";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Sun Mar 23 21:18:10 +0000 2014";
"default_profile" = 1;
"default_profile_image" = 1;
description = "";
entities = {
description = {
urls = (
);
};
};
"favourites_count" = 0;
"follow_request_sent" = "<null>";
"followers_count" = 1;
following = "<null>";
"friends_count" = 6;
"geo_enabled" = 0;
id = 24072342084;
"id_str" = 242344084;
"is_translation_enabled" = 0;
"is_translator" = 0;
lang = en;
"listed_count" = 0;
location = "";
name = "My Name";
notifications = "<null>";
"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" = 0;
"profile_image_url" = "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png";
"profile_image_url_https" = "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = ScreenName;
"statuses_count" = 2;
"time_zone" = "<null>";
url = "<null>";
"utc_offset" = "<null>";
verified = 0;
};

最佳答案

你要找的后两个键在用户字典里,所以试试

t[@"user"][@"screen_name"];
t[@"user"][@"profile_image_url"];

解决第一个问题后会出现第二个问题。网址是一个字符串。要获得正确的 NSURL,您需要使用 NSURL 类方法。

NSURL *aURL = [NSURL URLWithString:t[@"user"][@"profile_image_url"]];

关于ios - 解析字典的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23507382/

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