0

I'm developing an Twitter app, but in the view where's supposed to be the logged user info, I'm not able to parse the JSON gave by [_engine getUserInformationFor:username];. I'm using SBJSON and tells me this when tries to parse it:

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

This is the code I'm using:

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"]);
The output that [_engine getUserInformationFor:username]; gaves me is:


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;
    }

I think it's JSON, but not sure. I also tried with the url twitter gives but didn't got to work too. The URL is http://api.twitter.com/1/users/show.json?screen_name=zad0xsis , where "zad0xsis" is the twitter username.

Thanks in advance!! ;)

pmerino
  • 5,900
  • 11
  • 57
  • 76
  • This is no valid json, sorry. – Nick Weaver May 07 '11 at 10:41
  • Then any way to parse it out of http://api.twitter.com/1/users/show.json?screen_name=zad0xsis ? thanks for your response :) – pmerino May 07 '11 at 11:00
  • Oh that link returns valid json. There seems to be something wrong with the `getUserInformationFor` method. – Nick Weaver May 07 '11 at 11:06
  • I tried using the link but I can't get it to parse :( I get this `2011-05-07 13:15:20.351 BirdieApp[7833:40b] -JSONValue failed. Error is: Unrecognised leading character at offset 0`. Now I used this instead of getUserInformationFor: `NSString *userinfo = [NSString stringWithFormat:@"http://api.twitter.com/1/users/show.json?screen_name=%@", username];` – pmerino May 07 '11 at 11:16

2 Answers2

1

Hii. Here is a good link OAuth Twitter

This example uses model to get json result in NSDictionary .They called getUsertimeLine method . You can call your own method.

Abhishek
  • 303
  • 1
  • 6
  • 25
0

My experience with Cocoa & JSON is

  • It just won't work right...
  • or It's not worth all of the trouble to parse it!

You might be better off using the Twitter XML API

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

Then using NSXMLParser to parse it (on iPhone): http://ll.io/e17

or

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

Hope this helps!

Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
Hunter Dolan
  • 497
  • 1
  • 6
  • 16
  • IMHO: XML parsing is a horror, especially in Objective-C. Sorry but JSON is a good format and the json parsing libraries out there are good enough, you just have to know how to use them. – Nick Weaver May 07 '11 at 12:32
  • Then any easy way of parse the JSON/XML gave in the URL? ;) – pmerino May 07 '11 at 13:55