Objective c 将服务器输出值作为NSInteger
我正在尝试调用php脚本,通过我的iphone应用程序返回一个整数值作为服务器输出Objective c 将服务器输出值作为NSInteger,objective-c,nsinteger,Objective C,Nsinteger,我正在尝试调用php脚本,通过我的iphone应用程序返回一个整数值作为服务器输出 NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]]; NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding]; NSInteger *
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSInteger * userid = [serverOutput integerValue];
NSLog(@" %d" , userid);
但是如果我的print my serverOutput字符串是2381164503,但我的NSLog@%d,userid会将我打印为2147483647。我不知道为什么它在解析不同的值:首先,NSInteger是一个基本类型,所以不应该通过在前面放星号来声明userid作为指针。其次,值2381164503对于NSInteger最大值2147483647来说太大 尝试使用long-long替换:
long long userid = [serverOutput longLongValue];
NSLog(@" %lld" , userid); //use %lld instead of %d