1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

JSON in iPhone

Discussion in 'iPhone/iPad Programming' started by vineesh, Aug 4, 2012.

  1. macrumors newbie

    #1
    I have a JSON formated file for Time API , How can I display it. please help me

    jsont({
    "id": "ntp-a1.nict.go.jp",
    "it": 1232963971.248,
    "st": 1344075932.199,
    "leap": 34,
    "next": 1341100800,
    "step": 1
    })

    Thank You.
     
  2. macrumors 603

    ArtOfWarfare

    #2
    What have you tried? Without knowing what you've tried, we have no way of gauging how much to tell you. We could waste our time explaining too much to you, and your time in making you read it all, or we could not explain it enough and go clear over your head.

    Try making that an NSString and parsing it, I think. IDK, I haven't actually worked with JSON ever. (Mostly focus on answering what you've tried. It'll help others who know more to help you.)
     
  3. macrumors 68000

    #3
    Ditto to what ArtOfWarfare said.

    Have you tried searching in the iOS developer documentation for the word JSON. I know for a fact you'll find something.
     
  4. macrumors regular

    #4
  5. vineesh, Aug 6, 2012
    Last edited by a moderator: Aug 6, 2012

    macrumors newbie

    #5
    I trie like this,

    Code:
    NSError *error;
        NSString *str=@"http://ntp-a1.nict.go.jp/cgi-bin/jsont?1232963971.248";
        NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
        
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
        
        NSObject *idOBject=[dic objectForKey:@"id"];
        NSObject *itObject=[dic objectForKey:@"it"];
        
        NSLog(@"Id: %@",idOBject);
        NSLog(@"It: %@",itObject);

    But it get null value.
     
  6. macrumors 603

    ArtOfWarfare

    #6
    You convert a string to data, then interpret that data as a JSON, but it's not, it's a string. That's why you're getting null.

    Read the tutorial from Ray Wenderlich someone posted above (on mobile so I can't look back at who it was) - it'll cover downloading the data.
     
  7. vineesh, Aug 10, 2012
    Last edited by a moderator: Aug 10, 2012

    macrumors newbie

    #7
    Ok, thanks, I solved my issue?

    I successfully Parsed from json.
     
  8. Moderator

    dejo

    Staff Member

    #8
    I'm just curious: how are you browsing the forums on your mobile that you can't see who made previous posts?
     

Share This Page