Iphone 在cocoa中使用JSON

Iphone 在cocoa中使用JSON,iphone,cocoa,cocoa-touch,json,Iphone,Cocoa,Cocoa Touch,Json,我正在使用cocoa JSON框架 这是我得到的JSON输出的结果。我可以在字典里看到结果 Response { "completed_in" = 0.02461; "max_id" = 10088639298; "next_page" = "?page=2&max_id=10088639298&q=apple"; page = 1; query = apple; "refresh_url" = "?since_id=10088639298&q=apple"; resul

我正在使用cocoa JSON框架

这是我得到的JSON输出的结果。我可以在字典里看到结果

Response {
"completed_in" = 0.02461;
"max_id" = 10088639298;
"next_page" = "?page=2&max_id=10088639298&q=apple";
page = 1;
query = apple;
"refresh_url" = "?since_id=10088639298&q=apple";
results =     (
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:09 +0000";
        "from_user" = leduxcwb;
        "from_user_id" = 69744637;
        geo = <null>;
        id = 10088639298;
        "iso_language_code" = pt;
        "profile_image_url" = "http://a3.twimg.com/profile_images/459490475/Backup_of_Ledux_LOGO_FUNDO_2_normal.jpg";
        source = "&lt;a href=&quot;http://echofon.com/&quot; rel=&quot;nofollow&quot;&gt;Echofon&lt;/a&gt;";
        text = "FOTOS NOVAS - B-DAY Apple Carraro @applecarraro com @smccarraro @letsdoitbetter Bogus e muito mais - LEDUXcwb - http://bit.ly/9W2GOn";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:09 +0000";
        "from_user" = BIEBERBAABY;
        "from_user_id" = 87598715;
        geo = <null>;
        id = 10088639165;
        "profile_image_url" = "http://a3.twimg.com/profile_images/736057781/lmaaao__angell_muucch_normal.jpg";
        source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
        text = "RT @justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:08 +0000";
        "from_user" = TheFerstFamily;
        "from_user_id" = 5186275;
        geo = <null>;
        id = 10088638658;
        "iso_language_code" = en;
        "profile_image_url" = "http://a1.twimg.com/profile_images/80538644/Sherri_and_Tom_normal.jpg";
        source = "&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;";
        text = "Apple &amp; Honeysuckle Refreshing Body Spray  30% off and free shipping http://tinyurl.com/yapqsqf at Bonanzle.";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:07 +0000";
        "from_user" = nappypoet;
        "from_user_id" = 3727061;
        geo = <null>;
        id = 10088638027;
        "iso_language_code" = en;
        "profile_image_url" = "http://a3.twimg.com/profile_images/603999315/DSCN1910_normal.JPG";
        source = "&lt;a href=&quot;http://m.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;mobile web&lt;/a&gt;";
        text = "APPLE STORE!!!!!!!!!!!!";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:06 +0000";
        "from_user" = morningnew;
        "from_user_id" = 90568021;
        geo = <null>;
        id = 10088637474;
        "iso_language_code" = en;
        "profile_image_url" = "http://a1.twimg.com/profile_images/632625890/11238_1187063001649_1380523419_30571850_5695474_n_normal.jpg";
        source = "&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;";
        text = "latest video clip Chile, test and keep brand new APPLE iPad here http://bit.ly/ctyW2C [CA people Only]";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:05 +0000";
        "from_user" = "MaddieT_Love";
        "from_user_id" = 36657123;
        geo = <null>;
        id = 10088637057;
        "iso_language_code" = en;
        "profile_image_url" = "http://a3.twimg.com/profile_images/672448029/zzz____normal.jpg";
        source = "&lt;a href=&quot;http://www.myspace.com/sync&quot; rel=&quot;nofollow&quot;&gt;MySpace&lt;/a&gt;";
        text = "TELLiNG OFF KiERSTEN!!!! haha &quot;if yu painted her red,, she'd be a GIANT apple!!!!&quot; (:";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:04 +0000";
        "from_user" = TechPsychic;
        "from_user_id" = 65162673;
        geo = <null>;
        id = 10088636187;
        "iso_language_code" = en;
        "profile_image_url" = "http://a1.twimg.com/profile_images/449688160/dragon_normal.jpg";
        source = "&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;";
        text = "Apple announced a beta Launch a status online is trying to which has.";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:03 +0000";
        "from_user" = sallyroyerderr;
        "from_user_id" = 15188311;
        geo = <null>;
        id = 10088635728;
        "iso_language_code" = en;
        "profile_image_url" = "http://a3.twimg.com/profile_images/616259477/IMG_2013_normal.jpg";
        source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
        text = "Apple cake and coffee...delicious!";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:35:02 +0000";
        "from_user" = "steve_widen";
        "from_user_id" = 93551780;
        geo = <null>;
        id = 10088634985;
        "iso_language_code" = en;
        "profile_image_url" = "http://a1.twimg.com/profile_images/664143910/stevetweet_normal.jpg";
        source = "&lt;a href=&quot;http://www.hootsuite.com&quot; rel=&quot;nofollow&quot;&gt;HootSuite&lt;/a&gt;";
        text = "Apple's Academy Award For Product Placement | http://ow.ly/1f3dD";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:58 +0000";
        "from_user" = LessiaFetsch;
        "from_user_id" = 100092422;
        geo = <null>;
        id = 10088633257;
        "iso_language_code" = ru;
        "profile_image_url" = "http://a3.twimg.com/profile_images/669973111/4_normal.jpg";
        source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
        text = "\U043f\U043e\U0434\U0430\U0440\U0438\U043b\U0438 apple magic mouse, \U0441\U0438\U0436\U0443 \U043b\U043e\U043c\U0430\U044e \U0433\U043e\U043b\U043e\U0432\U0443,\U043a\U0430\U043a \U0436 \U0435\U0451 \U043d\U0430\U0441\U0442\U0440\U043e\U0438\U0442\U044c :D \U043d\U0443 \U0434\U0430,\U044f \U0447\U0430\U0439\U043d\U0438\U043a \U0438 \U0447\U0442\U043e :D";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:57 +0000";
        "from_user" = "I_Dont_Cin";
        "from_user_id" = 80004560;
        geo = <null>;
        id = 10088632392;
        "iso_language_code" = en;
        "profile_image_url" = "http://a3.twimg.com/profile_images/735462983/I_Dont_Cin_normal.jpg";
        source = "&lt;a href=&quot;http://echofon.com/&quot; rel=&quot;nofollow&quot;&gt;Echofon&lt;/a&gt;";
        text = "RT @girlKell: these sour apple bitter bitches im not fucking with them";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:54 +0000";
        "from_user" = maddenkatie;
        "from_user_id" = 80572995;
        geo = <null>;
        id = 10088631073;
        "profile_image_url" = "http://a1.twimg.com/profile_images/712744500/19150_1342329082633_1363398519_30948030_6001641_n_normal.jpg";
        source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
        text = "RT @justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:54 +0000";
        "from_user" = SirKnowsALot;
        "from_user_id" = 90229447;
        geo = <null>;
        id = 10088630768;
        "iso_language_code" = en;
        "profile_image_url" = "http://s.twimg.com/a/1267816830/images/default_profile_5_normal.png";
        source = "&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;";
        text = "http://ow.ly/WEWQ I wrote a tutorial called How to create iPhone ringtones using only iTunes. It's not that hard. #apple #mp3 #aac #free";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:39 +0000";
        "from_user" = ronbentata;
        "from_user_id" = 51909217;
        geo = <null>;
        id = 10088623134;
        "iso_language_code" = en;
        "profile_image_url" = "http://a3.twimg.com/profile_images/544679831/IMG_3998_z_normal.jpg";
        source = "&lt;a href=&quot;http://www.linkedin.com/&quot; rel=&quot;nofollow&quot;&gt;LinkedIn&lt;/a&gt;";
        text = "Apple's stock reaches a new high - almost $220. wish i have a few (a lot actually)";
        "to_user_id" = <null>;
    },
            {
        "created_at" = "Sat, 06 Mar 2010 20:34:38 +0000";
        "from_user" = MikaylaFenty;
        "from_user_id" = 70426321;
        geo = <null>;
        id = 10088622471;
        "profile_image_url" = "http://a3.twimg.com/profile_images/722158465/selena_gomez_normal.jpg";
        source = "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;";
        text = "RT @justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
        "to_user_id" = <null>;
    }
);
"results_per_page" = 15;
"since_id" = 0;

如何获得完整的结果字典?

这不是有效的JSON语法;这是模糊的接近,但它也是非常错误的。但是,我不太确定您在这里要问什么。

这不是有效的JSON语法;这是模糊的接近,但它也是非常错误的。不过,我不太清楚你在问什么。

你在这样做吗

NSArray *array = /*can has object from JSON kplzthx*/;
for (id obj in array) {
    NSLog(@"Current Object type: %@; object: %@", [obj class], obj);
}
解析的结果不是一个数组,而是一个字典,它的键是
@“completed\u in”
@“max\u id”
,等等。这些键就是你在这个循环中得到的:在字典上循环会产生它的键(不是以任何特定的顺序)

请注意,告诉编译器该变量将包含指向NSArray的指针并不意味着它将;如果上面的代码类似于您的代码,那么您将把一个指向NSDictionary(JSON解析器创建并返回给您)的指针放入该变量中。编译器无法预测这一点;它只能相信你说的话

你到底想要什么还不清楚。如果您想在结果字典数组上循环,那么请询问JSON解析器为键
@“results”
的对象返回给您的字典;该对象将是字典数组

如果您只是想获得表示JSON数据完整解析的顶级字典:恭喜您;你有。它是JSON解析器返回给您的对象

或者,在代码中:

NSDictionary *topLevelDictionary = /*object from JSON parser*/;
NSArray *resultDictionaries = [topLevelDictionary objectForKey:@"results"];
你在这么做吗

NSArray *array = /*can has object from JSON kplzthx*/;
for (id obj in array) {
    NSLog(@"Current Object type: %@; object: %@", [obj class], obj);
}
解析的结果不是一个数组,而是一个字典,它的键是
@“completed\u in”
@“max\u id”
,等等。这些键就是你在这个循环中得到的:在字典上循环会产生它的键(不是以任何特定的顺序)

请注意,告诉编译器该变量将包含指向NSArray的指针并不意味着它将;如果上面的代码类似于您的代码,那么您将把一个指向NSDictionary(JSON解析器创建并返回给您)的指针放入该变量中。编译器无法预测这一点;它只能相信你说的话

你到底想要什么还不清楚。如果您想在结果字典数组上循环,那么请询问JSON解析器为键
@“results”
的对象返回给您的字典;该对象将是字典数组

如果您只是想获得表示JSON数据完整解析的顶级字典:恭喜您;你有。它是JSON解析器返回给您的对象

或者,在代码中:

NSDictionary *topLevelDictionary = /*object from JSON parser*/;
NSArray *resultDictionaries = [topLevelDictionary objectForKey:@"results"];

我相信提问者记录了解析的对象,这将是一个属性列表。这是有效的属性列表语法;然而,这个问题的措辞似乎是JSON本身,我相信提问者记录了解析后的对象,这将是一个属性列表。这是有效的属性列表语法;然而,这个问题的措辞似乎就是JSON本身。