gpt4 book ai didi

iphone - 解析 JSON Feed iOS 5

转载 作者:行者123 更新时间:2023-12-03 21:17:38 25 4
gpt4 key购买 nike

我对 iOS 开发还很陌生,我想解析 JSON twitter feed 的值,这样我就可以将它们拉入 tableView 中。

到目前为止,我已将提要中的信息以字符串形式记录到我的控制台栏中,但我不知道下一步该去哪里。

我当前的代码是:

- (void)loadTweets
{
NSString *twitterURL = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=evostikleague&count=%d", tweetCellCount];
NSURL *fullURL = [NSURL URLWithString:twitterURL];

NSError *error = nil;
NSData *dataURL = [NSData dataWithContentsOfURL:fullURL options:0 error:&error];

NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

NSLog(@"Everything:\n%@", strResult);
}

这为我提供了来自提要的原始数据:

[{"id_str":"171930825225551872","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Tue Feb 21 12:14:37 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171930825225551872,"retweet_count":1,"text":"The Evo-Stik Challenge: League announce sponsored bike ride from Wembley to Blackpool http:\/\/t.co\/23i8gC2N"},{"id_str":"171915587491078144","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Tue Feb 21 11:14:04 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171915587491078144,"retweet_count":0,"text":"Gingerbreads look to consolidate top spot: Grantham Town update, by Graham Cowell http:\/\/t.co\/FREdshtm"},{"id_str":"171633185870979074","coordinates":null,"in_reply_to_status_id_str":null,"place":null,"possibly_sensitive":false,"geo":null,"in_reply_to_user_id_str":null,"favorited":false,"created_at":"Mon Feb 20 16:31:54 +0000 2012","user":{"id":148344608,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","created_at":"Wed May 26 13:24:44 +0000 2010","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_text_color":"333333","time_zone":null,"following":null,"followers_count":2441,"profile_sidebar_border_color":"C0DEED","screen_name":"evostikleague","verified":false,"utc_offset":null,"default_profile_image":false,"location":"UK","name":"The Evo-Stik League","notifications":null,"profile_background_tile":false,"favourites_count":0,"id_str":"148344608","profile_sidebar_fill_color":"DDEEF6","contributors_enabled":false,"protected":false,"show_all_inline_media":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1041551481\/twitter_logo_normal.jpg","profile_background_color":"C0DEED","description":"","default_profile":true,"lang":"en","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","statuses_count":1296,"geo_enabled":false,"profile_link_color":"0084B4","follow_request_sent":null,"friends_count":178,"listed_count":43,"profile_use_background_image":true,"url":"http:\/\/www.evostikleague.co.uk\/"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"retweeted":false,"in_reply_to_status_id":null,"contributors":null,"truncated":false,"source":"\u003Ca href=\"http:\/\/twitterfeed.com\" rel=\"nofollow\"\u003Etwitterfeed\u003C\/a\u003E","id":171633185870979074,"retweet_count":1,"text":"Chasetown unveil \u00a310k Makeover: Premier Division club won Evo-Stik Facilities Makeover competition http:\/\/t.co\/ywf74N9f"}]

然后我想将其放入一个数组中,这样我就可以增加返回结果的数量,然后循环并将它们显示在表格中。

最佳答案

在 iOS 5 中,Apple 终于公开了他们的 JSON 解析器。

尝试查看NSJSONSerialization

您的代码可能如下所示,但我建议先阅读文档。

    NSArray* yourArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:someError]

关于iphone - 解析 JSON Feed iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9378853/

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