当我尝试反序列化在 Web 服务中打印出的 JSON 代码时,我继续收到此错误。
这是在 php 中打印的内容:
[{"reply":"yes","admin1":"1066","admin2":"1635"}]
这是我在目标 c 中反序列化 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);
请让我知道此代码或 JSON 格式是否有任何问题