PDA

View Full Version : JSON in iPhone




vineesh
Aug 4, 2012, 06:21 AM
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
Aug 4, 2012, 07:30 AM
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
Aug 4, 2012, 10:57 AM
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.

ahan.tm
Aug 4, 2012, 02:39 PM
Ray Wenderlich has a great tutorial for parsing JSON in iOS5:
http://www.raywenderlich.com/5492/working-with-json-in-ios-5
(http://www.raywenderlich.com/5492/working-with-json-in-ios-5)

vineesh
Aug 6, 2012, 03:52 AM
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,

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.

ArtOfWarfare
Aug 6, 2012, 05:36 AM
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
Aug 10, 2012, 03:49 AM
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.

dejo
Aug 10, 2012, 08:41 AM
...(on mobile so I can't look back at who it was)...

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