Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS 5 Json Serialization
    text
    copied!<p>I have used JSON Serialization to get json response, here i'mn getting all fine, but when i need to post some values as key value pair with the URL. I have done like this, but didn't get the result. </p> <pre><code>NSArray *objects = [NSArray arrayWithObjects:@"uname", @"pwd", @"req",nil]; NSArray *keys = [NSArray arrayWithObjects:@"ann", @"ann", @"login", nil]; NSDictionary *dict = [NSDictionary dictionaryWithObjects:keys forKeys:objects]; if ([NSJSONSerialization isValidJSONObject:dict]) { NSError *error; result = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&amp;error]; if (error == nil &amp;&amp; result != nil) { // NSLog(@"Success"); } } NSURL * url =[NSURL URLWithString:@"URL_address_VALUE/index.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:[NSString stringWithFormat:@"%d",[result length]] forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:result]; NSURLResponse *res = nil; NSError *error = nil; NSData *ans = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;res error:&amp;error]; if (error == nil) { NSString *strData = [[NSString alloc]initWithData:ans encoding:NSUTF8StringEncoding]; NSLog(@"%@",strData); } </code></pre> <p>I don't know what goes wrong here... Please dudes help me..</p>
 

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