Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I continue to get this error when I try to deserialize the JSON code that is printed out in the web service.

This is what is being printed out in php:

[{"reply":"yes","admin1":"1066","admin2":"1635"}]

This is my code in objective c to deserialize the json:

     NSMutableString *loginString = [NSMutableString stringWithString:kLoginURL];

[loginString appendString:[NSString stringWithFormat:@"?username=%@",username.text]];
[loginString appendString:[NSString stringWithFormat:@"&password=%@",password.text]];
[loginString setString:[loginString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"%@",loginString);
NSURL *url = [NSURL URLWithString:loginString];
//NSError *error1;

NSData *data = [NSData dataWithContentsOfURL:url ];
//NSLog(@"%@",data);
// NSLog(@"error %@",error1);
NSError *error;
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"json error:  %@",error);
NSLog(@"%@",json);
NSDictionary *info = [json objectAtIndex:0];
NSLog(@"%@",info);
NSString *reply = [info objectForKey:@"reply"];
NSLog(@"%@",reply);

Please let me know if there is anything wrong with this code or the format of JSON

share|improve this question
2  
Just for sanity why not print out the contents of data, eg: NSLog(@"data contents: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); –  Nicholas Hart Jul 19 at 20:35
 
Thank you @nicholas for that tip. You just saved my life ;) –  Will Oct 14 at 18:03

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.