iOS JSON in iPhone

vineesh

macrumors newbie
Original poster
Jan 22, 2012
9
0
Cochin
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,579
4,019
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.)
 

xStep

macrumors 68020
Jan 28, 2003
2,006
99
Less lost in L.A.
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.
 

vineesh

macrumors newbie
Original poster
Jan 22, 2012
9
0
Cochin
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.)
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.
 
Last edited by a moderator:

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,579
4,019
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.
 

vineesh

macrumors newbie
Original poster
Jan 22, 2012
9
0
Cochin
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.
Ok, thanks, I solved my issue?

I successfully Parsed from json.
 
Last edited by a moderator: