0

大家好,我试图通过我的 iphone 应用程序调用 php 脚本,该应用程序返回一个整数值作为 serverOutput

NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
    NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];

    NSInteger * userid  = [serverOutput integerValue];

    NSLog(@" %d" , userid);

但是如果我打印我的 serverOutput 字符串它是2381164503但我的 NSLog(@" %d" , userid) 打印我2147483647。我不知道由于某种原因它正在解析不同的值:(

4

1 回答 1

0

First, NSInteger is a primitive type so you shouldn't declare userid as a pointer (by putting the asterisk in front). Second, the value 2381164503 is too big for an NSInteger (max is 2147483647).

Try using a long long instead:

long long userid = [serverOutput longLongValue];
NSLog(@" %lld" , userid);  //use %lld instead of %d
于 2011-04-26T15:54:29.383 回答