我可以通过 NSJSONSerialization 序列化负整数吗?

Can I serialize negative integer by NSJSONSerialization?

我无法通过 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"]);