我无法通过 NSJSONSerialization 序列化负整数。
objective-C :
NSMutableDictionary *sendData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@480, @"width",
@800, @"height"
@-10, @"value1",
@10, @"value2", nil];
NSError *error = nil;
NSData *dataJSon = [NSJSONSerialization dataWithJSONObject:sendData options:0 error:&error];
NSLog(@"sendData\n %@ \n\n", [sendData description]);
日志
sendData{
width = 480; // int
height = 800; // int
value1 = "-10"; // string. Not integer!!
value2 = 10; // int
}
如何序列化负整数?
最佳答案
你是对的,一切都很好。这只是字典描述的误导。
NSMutableDictionary *sendData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:-10], @"value1",
[NSNumber numberWithInt:10], @"value2", nil];
NSError *error = nil;
NSData *dataJSon = [NSJSONSerialization dataWithJSONObject:sendData options:0 error:&error];
NSLog(@"sendData\n %@ \n\n", [sendData objectForKey:@"value1"]);
关于ios - 我可以通过 NSJSONSerialization 序列化负整数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30183526/