无法解析SA_OAuthTwitterEngine / MGTwitterEngine发送的JSON

时间:2011-05-07 10:37:27

标签: iphone ios sdk mgtwitterengine

我正在开发一个Twitter应用程序,但在视图中应该是已记录的用户信息,我无法解析[_engine getUserInformationFor:username];给出的JSON。我正在使用SBJSON并在尝试解析它时告诉我:

2011-05-07 12:29:45.553 BirdieApp[7122:40b] -JSONValue failed. Error is: Unrecognised leading character at offset 0

这是我正在使用的代码:

NSLog(@"loggedapi");
NSString *username = [_engine username];
NSString *userinfo = [_engine getUserInformationFor:username];
NSLog(@"user: %@%@", username, userinfo); NSArray *results = [userinfo JSONValue]; NSDictionary *first = [results objectAtIndex:0]; NSLog(@"screen name = %@", [first objectForKey:@"description"]);
[_engine getUserInformationFor:username];给我的输出是:


2011-05-07 12:29:46.281 BirdieApp[7122:40b] User Info Received: (
        {
        "contributors_enabled" = false;
        "created_at" = "Fri Sep 17 20:40:15 +0000 2010";
        "default_profile" = true;
        "default_profile_image" = false;
        description = "iPhone developer and Photoshop designer. \U30dd\U30fc\U30eb. I developed a web browser, it's called zad0xNET browser, search it in Cydia. Ofcourse this is a fake account!";
        "favourites_count" = 0;
        "follow_request_sent" = false;
        "followers_count" = 4;
        following = 0;
        "friends_count" = 1;
        "geo_enabled" = true;
        id = 191964939;
        "is_translator" = false;
        lang = es;
        "listed_count" = 0;
        location = "Castilla y Le\U00f3n, Espa\U00f1a";
        name = zad0xLOL;
        notifications = false;
        "profile_background_color" = C0DEED;
        "profile_background_image_url" = "http://a3.twimg.com/a/1304019356/images/themes/theme1/bg.png";
        "profile_background_tile" = false;
        "profile_image_url" = "http://a0.twimg.com/profile_images/1190671091/ProfilePhoto_normal.png";
        "profile_link_color" = 0084B4;
        "profile_sidebar_border_color" = C0DEED;
        "profile_sidebar_fill_color" = DDEEF6;
        "profile_text_color" = 333333;
        "profile_use_background_image" = true;
        protected = 0;
        "screen_name" = zad0xs1s;
        "show_all_inline_media" = true;
        "source_api_request_type" = 12;
        status =         {
            contributors = "";
            coordinates = "";
            "created_at" = "Sat May 07 07:42:18 +0000 2011";
            favorited = false;
            geo = "";
            id = 66769811828514816;
            "in_reply_to_screen_name" = zad0xs1s;
            "in_reply_to_status_id" = "";
            "in_reply_to_user_id" = 191964939;
            place = "";
            "retweet_count" = 0;
            retweeted = false;
            source = "BirdieApp";
            "source_api_request_type" = 12;
            text = "@zad0xs1s sdjdjdd";
            truncated = 0;
        };
        "statuses_count" = 16;
        "time_zone" = Madrid;
        url = "http://www.pabloxweb.es";
        "utc_offset" = 3600;
        verified = false;
    }

我认为这是JSON,但不确定。我也尝试了url twitter给出但是也没有工作。 URL为http://api.twitter.com/1/users/show.json?screen_name=zad0xsis,其中“zad0xsis”是推特用户名。

提前致谢!! ;)

2 个答案:

答案 0 :(得分:1)

斐伊川。 这是一个很好的链接OAuth Twitter

此示例使用model在NSDictionary中获取json结果。它们称为getUsertimeLine方法。你可以调用自己的方法。

答案 1 :(得分:0)

我对Cocoa& amp;的体验JSON是

  • 它不会正常工作......
  • 或者解析它并不值得所有麻烦!

您最好使用Twitter XML API

https://api.twitter.com/1/users/show.xml?screen_name=zad0xsis

然后使用NSXMLParser解析它(在iPhone上):http://ll.io/e17

NSXMLDocument(Mac):http://ll.io/ff0

希望这有帮助!