简体   繁体   English

从服务器端访问JSON

[英]acces JSON from server side

I have the following response from server: 我从服务器收到以下响应:

{"_license":false}

And when I try to get out from there _license it displays null .I tried like this: 当我尝试离开_license它显示为null

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

Any idea why?And how to solve? 知道为什么吗,以及如何解决?

Try en spilt up your code, don't do every thing in one line. 尝试en溢出您的代码,不要一every而就。 Then check ever variable if it contains the correct value. 然后检查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