【发布时间】:2012-02-28 14:55:39
【问题描述】:
我正在尝试从 Web 服务解析 JSON 字符串。传入的字符串如下所示:
{
"Faculty_Members": [
{
"ID": 3377,
"First_Name": "John",
"Last_Name": "Doe"
}
]
}
我的 IOS 代码如下所示:
NSURL *jsonUrl = [NSURL URLWithString:@"http://website/Service1.svc/Names"];
NSError *error = nil;
NSData *jsonData = [NSData dataWithContentsOfURL:jsonUrl options:kNilOptions error:&error];
NSMutableDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"%@",jsonResponse);
//parse out the json data
if([NSJSONSerialization isValidJSONObject:jsonResponse])
{
NSLog(@"YEP");
}else{
NSLog(@"NOPE");
}
日志将显示正确的 JSON 数据,但我在 isValidJsonObject 上不断收到“NOPE”。
Web 服务正在将数据作为数据类型“字符串”发回。这有什么区别吗?如果是这样,我应该将它发送回什么数据类型?
任何想法将不胜感激!
【问题讨论】:
-
我正在尝试解析相同类型的 dic。并遇到问题。 @NeedSomeAnswers,如果您有任何解决方案并发布。