Thursday, March 24, 2011

json framework

Simple step to teach you how to implement json framework to parse json string



Example



HTTP POST Restful

NSDictionary *data = [[NSDictionary alloc] initWithObjectsAndKeys:
username, USERNAMEKEY,
password, PASSWORDKEY,
nil];
SBJsonWriter *json = [SBJsonWriter alloc];
NSString *jsonString = [json stringWithObject:data];
NSLog(jsonString);


[data release];
[json release];

//create/send http post request
NSData *postData = [jsonString dataUsingEncoding:NSASCIIStringEncoding];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://abc.appspot.com/api/login/"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

Full article

No comments:

Post a Comment