Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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.
 
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.)
 
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.
 
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:
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.
 
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:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.