I am working with the JSON library and see this situation:
Convert JSON string to NSDictionary
Scenario 1:
NSString *jsonString = @"{\"Name\":\"Foo\", Points:5}";
NSDictionary *dictionary = (NSDictionary*)[jsonParser objectWithString:jsonString];
NSLog(@"Dictionary: %@",dictionary);
I see the result as follows:
Dictionary: {Name = "Foo"; Points = 5; }
So right.
Scenario 2:
NSString *jsonString = @"{\"Name\":\"Foo\", Points:0.5}";
NSDictionary *dictionary = (NSDictionary*)[jsonParser objectWithString:jsonString];
NSLog(@"Dictionary: %@",dictionary);
I see the result as follows:
Dictionary: {Name = "Foo"; Dots = "0.5"; }
???
Scenario 3:
NSString *jsonString = @"{\"Name\":\"Foo\", Points:-1}";
NSDictionary *dictionary = (NSDictionary*)[jsonParser objectWithString:jsonString];
NSLog(@"Dictionary: %@",dictionary);
I see the result as follows:
Dictionary: {Name = "Foo"; Points = "-1"; }
???
Why does the JSON library convert negative numbers or a number less than 1 into a string? Do you know how to prevent this?
source
share