A JSON library for the iPhone. For more information and a tutorial visit http://www.mobileorchard.com/tutorial-json-over-http-on-the-iphone/
Get the latest version of the JSON framework
Use the JSON framework:
- (void)viewDidLoad { responseData = [[NSMutableData data] retain]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.server.com/jsonresponse"]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; [super viewDidLoad]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSDictionary *dict = [responseString JSONValue]; [responseData release]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [responseData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [responseData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {; NSLog([NSString stringWithFormat:@"Connection failed: %@", [error description]]); } |