如何将字典键放入数组中

时间:2012-06-16 05:56:13

标签: objective-c twrequest

我不太确定我在这里做错了什么,我已经把这些教程留给了这封信。这是我的问题,我有一个叫做dict的字典,它是TWRequest的结果 - 我知道它包含推文,因为我的日志细节。我现在正在尝试创建一个这个'text'元素的数组但是我的日志说数组的空白??!这是我的代码,任何帮助将不胜感激。谢谢

NSArray *allTweetText = [dict objectForKey:@"text"];
NSLog(@"WHERE IS THIS: %@", allTweetText);  
NSString *singleTweet = [allTweetText objectAtIndex:indexPath.row];
NSArray *parsedTweet = [singleTweet componentsSeparatedByString:@":"];


cell.myHeader.text = [parsedTweet objectAtIndex:0];
cell.myDetails.text = [parsedTweet objectAtIndex:1];
cell.myDate.text = [parsedTweet objectAtIndex:2];

这是我的日志输出..... GNU gdb 6.3.50-20050815(Apple版gdb-1708)(2011年8月15日16:03:10 UTC) 版权所有2004 Free Software Foundation,Inc。 GDB是免费软件,由GNU通用公共许可证涵盖,您就是 欢迎在某些条件下更改和/或分发它的副本。

Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to process 560.

2012-06-16 06:49:36.591 V4[560:207] WHERE IS THIS: (null)
2012-06-16 06:49:36.593 V4[560:207] WHERE IS THIS: (null)
2012-06-16 06:49:36.595 V4[560:207] WHERE IS THIS: (null)
2012-06-16 06:49:36.596 V4[560:207] WHERE IS THIS: (null)
2012-06-16 06:49:37.033 V4[560:1f03] Twitter response: {
    "completed_in" = "0.043";
    "max_id" = 213870694428184576;
    "max_id_str" = 213870694428184576;
    "next_page" = "?page=2&max_id=213870694428184576&q=euro2012";
    page = 1;
    query = euro2012;
    "refresh_url" = "?since_id=213870694428184576&q=euro2012";
    results =     (
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:41 +0000";
            "from_user" = bombenj;
            "from_user_id" = 240783256;
            "from_user_id_str" = 240783256;
            "from_user_name" = "Joe Bomben";
            geo = "<null>";
            id = 213870694428184576;
            "id_str" = 213870694428184576;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2187998849/Joey_20b_normal.jpeg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2187998849/Joey_20b_normal.jpeg";
            source = "&lt;a href=&quot;http://twitter.com/download/iphone&quot; rel=&quot;nofollow&quot;&gt;Twitter for iPhone&lt;/a&gt;";
            text = "RT @AlexButcher12: One of the longest weeks ever, but it's been class. Even Welbeck finally did something right. #euro2012 #England";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:34 +0000";
            "from_user" = paismuttaqin;
            "from_user_id" = 235785477;
            "from_user_id_str" = 235785477;
            "from_user_name" = "asisten haji muhidin";
            geo = "<null>";
            id = 213870664036261889;
            "id_str" = 213870664036261889;
            "iso_language_code" = in;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2311132920/4jqzlu9n0yvjgue6m7k9_normal.jpeg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2311132920/4jqzlu9n0yvjgue6m7k9_normal.jpeg";
            source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
            text = "RT @KampusBola: INFO: Dengan kekalahan dari Inggris, SWEDIA dipastikan menjadi negara ke-2 yang tersingkir dari #EURO2012, menyusul Republik Irlandia.";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:31 +0000";
            "from_user" = kopite32;
            "from_user_id" = 307835184;
            "from_user_id_str" = 307835184;
            "from_user_name" = "Omar, abu norah";
            geo = "<null>";
            id = 213870652027961345;
            "id_str" = 213870652027961345;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/1750305485/4598243_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/1750305485/4598243_normal.jpg";
            source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
            text = "Match Rating: (Sweden- England 9/10) one of the best 3 games in the euro so far in the tournament.. just exciting one! #euro2012";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:24 +0000";
            "from_user" = kojipunkrock;
            "from_user_id" = 275555918;
            "from_user_id_str" = 275555918;
            "from_user_name" = nabe;
            geo = "<null>";
            id = 213870621078204417;
            "id_str" = 213870621078204417;
            "in_reply_to_status_id" = 213863786203975680;
            "in_reply_to_status_id_str" = 213863786203975680;
            "iso_language_code" = ja;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/1731824655/image_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/1731824655/image_normal.jpg";
            source = "&lt;a href=&quot;http://twitter.com/download/iphone&quot; rel=&quot;nofollow&quot;&gt;Twitter for iPhone&lt;/a&gt;";
            text = "@puukyla \U6cb3\U672c\U3067\U306f\U3082\U3046\U7b11\U3048\U306a\U3044\U3063\U3059\U306d #tbs #Euro2012";
            "to_user" = puukyla;
            "to_user_id" = 280651026;
            "to_user_id_str" = 280651026;
            "to_user_name" = puukyla;
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:24 +0000";
            "from_user" = ElisabethDuran5;
            "from_user_id" = 609418234;
            "from_user_id_str" = 609418234;
            "from_user_name" = "Elisabeth Duran";
            geo = "<null>";
            id = 213870620683943936;
            "id_str" = 213870620683943936;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2311342555/DCIM78_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2311342555/DCIM78_normal.jpg";
            source = "&lt;a href=&quot;http://mobile.twitter.com&quot; rel=&quot;nofollow&quot;&gt;Mobile Web&lt;/a&gt;";
            text = "#euro2012 if you show youself too you will make me hot in several minutes http://t.co/UwQsmGoA";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:20 +0000";
            "from_user" = Pettit95;
            "from_user_id" = 295327392;
            "from_user_id_str" = 295327392;
            "from_user_name" = "Dean Pettit";
            geo = "<null>";
            id = 213870607132143616;
            "id_str" = 213870607132143616;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2165706548/munch_2012_03_31_144236_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2165706548/munch_2012_03_31_144236_normal.jpg";
            source = "&lt;a href=&quot;http://twitter.com/download/android&quot; rel=&quot;nofollow&quot;&gt;Twitter for Android&lt;/a&gt;";
            text = "RT @stamfordpigeon: Terry looks naked without that armband. Forget whatever he's been accused of, the truth is he is still the true captain &amp; leader. #Euro2012";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:20 +0000";
            "from_user" = rezzae94;
            "from_user_id" = 435928379;
            "from_user_id_str" = 435928379;
            "from_user_name" = "febry rezza onandio";
            geo = "<null>";
            id = 213870603273379840;
            "id_str" = 213870603273379840;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2307207509/IMG00393-20120316-0703_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2307207509/IMG00393-20120316-0703_normal.jpg";
            source = "&lt;a href=&quot;http://ubersocial.com&quot; rel=&quot;nofollow&quot;&gt;\U00dcberSocial for BlackBerry&lt;/a&gt;";
            text = "RT @otha_sc: Fol low Me #EURO2012 #1000ADAY #OPENFOLLOW #INSTANFOLLOW http://t.co/6C6mxBE7";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:19 +0000";
            "from_user" = "Nona_Euro2012";
            "from_user_id" = 434219378;
            "from_user_id_str" = 434219378;
            "from_user_name" = "Nona Euro 2012";
            geo = "<null>";
            id = 213870602430316546;
            "id_str" = 213870602430316546;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2292387068/nona_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2292387068/nona_normal.jpg";
            source = "&lt;a href=&quot;http://blackberry.com/twitter&quot; rel=&quot;nofollow&quot;&gt;Twitter for BlackBerry\U00ae&lt;/a&gt;";
            text = "*cium Parker* RT \"@fierblake: Selamat Siang..*smbil dadah dadah sm ibra* RT @Nona_Euro2012: Good Morning, My England \U263a\"";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:19 +0000";
            "from_user" = rifanakhmad;
            "from_user_id" = 131992519;
            "from_user_id_str" = 131992519;
            "from_user_name" = "Rifan Akhmad";
            geo = "<null>";
            id = 213870600639361025;
            "id_str" = 213870600639361025;
            "iso_language_code" = in;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2295321527/Editing_2031052012_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2295321527/Editing_2031052012_normal.jpg";
            source = "&lt;a href=&quot;http://blackberry.com/twitter&quot; rel=&quot;nofollow&quot;&gt;Twitter for BlackBerry\U00ae&lt;/a&gt;";
            text = "Juga lagu soundtracknya iklan \"penyegar cap badak\"@Liputan9: Karena #Euro2012, Lagu \"Begadang\" Dan \"Judi\" Bang Rhoma Jadi Top Request Radio\"";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:17 +0000";
            "from_user" = AfrizalAditya;
            "from_user_id" = 444414040;
            "from_user_id_str" = 444414040;
            "from_user_name" = "AFRIZAL ADITYA";
            geo = "<null>";
            id = 213870591172812800;
            "id_str" = 213870591172812800;
            "in_reply_to_status_id" = 213869718459789312;
            "in_reply_to_status_id_str" = 213869718459789312;
            "iso_language_code" = vi;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2294411946/tc7zthbd4lmc0srv01jf_normal.jpeg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2294411946/tc7zthbd4lmc0srv01jf_normal.jpeg";
            source = "&lt;a href=&quot;http://mobile.twitter.com&quot; rel=&quot;nofollow&quot;&gt;Mobile Web&lt;/a&gt;";
            text = "@fellyciousjambi ttg #EURO2012 min :DD";
            "to_user" = FellyciousJAMBI;
            "to_user_id" = 519604225;
            "to_user_id_str" = 519604225;
            "to_user_name" = "MRS.ONLINE SHOP";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:14 +0000";
            "from_user" = "day_az";
            "from_user_id" = 54593972;
            "from_user_id_str" = 54593972;
            "from_user_name" = "Day Az";
            geo = "<null>";
            id = 213870579546198016;
            "id_str" = 213870579546198016;
            "iso_language_code" = ru;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/301917015/i_normal.jpeg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/301917015/i_normal.jpeg";
            source = "&lt;a href=&quot;http://twitterfeed.com&quot; rel=&quot;nofollow&quot;&gt;twitterfeed&lt;/a&gt;";
            text = "\U041f\U0435\U0440\U0432\U044b\U0435 \U0443\U0447\U0430\U0441\U0442\U043d\U0438\U043a\U0438 \U043f\U043b\U0435\U0439-\U043e\U0444\U0444 \U0415\U0412\U0420\U041e-2012 \U043e\U043f\U0440\U0435\U0434\U0435\U043b\U044f\U044e\U0442\U0441\U044f (\U041e\U041f\U0420\U041e\U0421) http://t.co/oM8dA830";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:08 +0000";
            "from_user" = Timpireofthesun;
            "from_user_id" = 150514655;
            "from_user_id_str" = 150514655;
            "from_user_name" = "Timmy Russell";
            geo = "<null>";
            id = 213870555428954113;
            "id_str" = 213870555428954113;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2177697758/image_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2177697758/image_normal.jpg";
            source = "&lt;a href=&quot;http://www.tumblr.com/&quot; rel=&quot;nofollow&quot;&gt;Tumblr&lt;/a&gt;";
            text = "Photo: England!! Carroll Walcott and wellbeck #euro #2012 #euro2012 #europe #england (Taken with Instagram) http://t.co/CzDtz0WP";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:06 +0000";
            "from_user" = lalainlaw;
            "from_user_id" = 400505062;
            "from_user_id_str" = 400505062;
            "from_user_name" = "Willa lala fitria \U266c";
            geo = "<null>";
            id = 213870545681387520;
            "id_str" = 213870545681387520;
            "iso_language_code" = es;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2312241367/koi_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2312241367/koi_normal.jpg";
            source = "&lt;a href=&quot;http://blackberry.com/twitter&quot; rel=&quot;nofollow&quot;&gt;Twitter for BlackBerry\U00ae&lt;/a&gt;";
            text = "RT @otha_sc: Follow_Me #EURO2012 #1000ADAY #OPENFOLLOW #INSTANFOLLOW http://t.co/BBehU3J1";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:05 +0000";
            "from_user" = YvonneAdelya05;
            "from_user_id" = 350094345;
            "from_user_id_str" = 350094345;
            "from_user_name" = "Yvonne Adelya So";
            geo = "<null>";
            id = 213870541730361344;
            "id_str" = 213870541730361344;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/2302248185/Screen_20120606_15002_normal.jpg";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/2302248185/Screen_20120606_15002_normal.jpg";
            source = "&lt;a href=&quot;http://www.pay4tweet.com&quot; rel=&quot;nofollow&quot;&gt;Pay4Tweet&lt;/a&gt;";
            text = "RT @TeamFollowWacky: RETWEET 4 '10,000' FOLLOWERS! http://t.co/2zLY4pd1 - C'MON #ENGLAND #EURO2012! SWEDEN 2 - 3 ENGLAND!!!! CONGRATULATIONS!!!\n #ad";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        },
                {
            "created_at" = "Sat, 16 Jun 2012 05:48:04 +0000";
            "from_user" = europakampioen;
            "from_user_id" = 456962739;
            "from_user_id_str" = 456962739;
            "from_user_name" = "Europees Kampioen ";
            geo = "<null>";
            id = 213870539096326147;
            "id_str" = 213870539096326147;
            "iso_language_code" = en;
            metadata =             {
                "result_type" = recent;
            };
            "profile_image_url" = "http://a0.twimg.com/profile_images/1737918047/europakampioen_normal.png";
            "profile_image_url_https" = "https://si0.twimg.com/profile_images/1737918047/europakampioen_normal.png";
            source = "&lt;a href=&quot;http://www.echofon.com/&quot; rel=&quot;nofollow&quot;&gt;Echofon&lt;/a&gt;";
            text = "RT @arminvanbuuren: Kharkov!!! Just finished playing. Crazy!!! We're ready!!! #neddui #euro2012 http://t.co/YjUhrkpY";
            "to_user" = "<null>";
            "to_user_id" = 0;
            "to_user_id_str" = 0;
            "to_user_name" = "<null>";
        }
    );
    "results_per_page" = 15;
    "since_id" = 0;
    "since_id_str" = 0;
}
2012-06-16 06:49:38.235 V4[560:207] WHERE IS THIS: (null)

1 个答案:

答案 0 :(得分:1)

对我而言,您的 dict 字典中似乎没有关键字“text”。但是你有关键的结果。如果你执行

NSArray results = [dict objectForKey:@"results"];

你将获得包含NSDictionaries的NSArray。那些嵌套的词典有关键的“文本”。所以你需要迭代数组结果

NSMutableArray *allTweetText = [NSMutableArray array];

for (NSDictionary *result in results) {
    NSString *text = [result objectForKey:@"text"];
    [allTweetText addObject:text];
}