繁体   English   中英

从服务器端访问JSON

[英]acces JSON from server side

我从服务器收到以下响应:

{"_license":false}

当我尝试离开_license它显示为null

NSString *items = [[parser objectWithString:[request responseString] error:nil] valueForKey:@"_license"];
NSLog(@"response server%@", items);

知道为什么吗,以及如何解决?

尝试en溢出您的代码,不要一every而就。 然后检查ever变量是否包含正确的值。

NSLog(@"Server response: %@",[request responseString]);
NSError * error = nil;

NSDictionary *response = [parser objectWithString:[request responseString] error:&error]

if (!response)( {
  NSLog( @"Error parsing JSON: %@", error);
  return;
}

NSLog(@"Dictionary: %@", response);

NSNumber *hasValidLicense = [response objectForKey:@"_license"];
NSLog(@"Has valid license: %@", hasValidLicense);

if ([hasValidLicense boolValue]){
   //Yes we have a valid license.
} else {
   // No valid license.
}

用以下内容替换您的行:

BOOL items = [[[parser objectWithString:[request responseString] error:nil] valueForKey:@"_license"] boolValue];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM