NSDebugDescription = JSON文本不以数组或对象和选项开头,以允许未设置片段

时间:2013-07-19 19:46:08

标签: php ios objective-c json

当我尝试反序列化在Web服务中打印出的JSON代码时,我继续收到此错误。

这是在php中打印出来的内容:

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

这是我在反序列化json的目标c中的代码:

     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格式

有任何问题,请与我们联系

0 个答案:

没有答案