我真的无法弄清楚如何将大NSNumber转换为NSString(4h谷歌搜索没有解决我的问题,并尝试了所有建议的解决方案 - stringValue,NSNumberFormatter,NSDecimalNumber)。
目前我以这种方式转换:
[NSString stringWithFormat:@"%llu", [largeNumber unsignedLongLongValue]];
一切正常,数字较小,但较大,我得到错误的字符串:(示例:输入数字是10202713632509569,但返回的字符串是10202713632509568.如何以适当的方式将NSNumber转换为NSString?
我通过AFNetworking框架从JSON响应中获得NSNumber。
我的JSON:
{
"author": {
"name": "Open Graph Test User",
"social_type": "facebook",
"id": 10202713632509569
}
}
我的代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager new];
manager.responseSerializer = [AFJSONResponseSerializer new];
[manager GET:@"/api/author"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSNumber *largeNumber = responseObject[@"author"][@"social_id"];
// ...
NSString *callPath = [NSString stringWithFormat:@"/profile/%@/%@", _userSocialType, [NSString stringWithFormat:@"%llu", [largeNumber unsignedLongLongValue]]];
// ...
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// ...
}
}];