Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the code which work for JSON post request, TouchJSON Framework is used for parsing the JSON, thanks 'schwa'.</p> <pre><code>NSArray *keys = [NSArray arrayWithObjects:@"username", @"password", @"preference", @"uid", nil]; NSArray *objects = [NSArray arrayWithObjects:@"accuser", @"accpass", @"abc_region", @"100", nil]; NSDictionary *theRequestDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSURL *theURL = [NSURL URLWithString:@"http://url.com/request.php"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f]; [theRequest setHTTPMethod:@"POST"]; [theRequest setValue:@"application/json-rpc" forHTTPHeaderField:@"Content-Type"]; NSString *theBodyString = [[CJSONSerializer serializer] serializeDictionary:theRequestDictionary]; NSLog(@"%@", theBodyString); NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding]; // NSLog(@"%@", theBodyData); [theRequest setHTTPBody:theBodyData]; NSURLResponse *theResponse = NULL; NSError *theError = NULL; NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&amp;theResponse error:&amp;theError]; NSString *theResponseString = [[[NSString alloc] initWithData:theResponseData encoding:NSUTF8StringEncoding] autorelease]; NSLog(theResponseString); NSDictionary *theResponseDictionary = [[CJSONDeserializer deserializer] deserialize:theResponseString]; NSLog(@"%@", theResponseDictionary); NSString *theGreeting = [theResponseDictionary objectForKey:@"greeting"]; [self setValue:theGreeting forKey:@"greeting"]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload