简体   繁体   中英

ios double quotes on dictionary when decimal point added

Im interacting with JSON, for "get" it works ok,

But with the "post", I have an error as the dictionary objects are surrounded with double quotes ""

and for the web service, i get an error for the double quotes, the problem is that if i use a dot to indicate a decimal point then the double quotes appear,

NSMutableDictionary *dicto = [[NSMutableDictionary alloc]init];

[dicto setObject:@"-33.82007932" forKey:@"Latitude"];

[dicto setObject:@"151.1850004" forKey:@"Longitude"];
[dicto setObject:@"10728" forKey:@"TransmissionAreaId"];
[dicto setObject:@"[11278,10747,10728,11503]" forKey:@"OtherTransmissionAreaIds"];

this is the log

2011-10-10 17:28:47.265 MySwitch[14632:707] the dictionary { Latitude = "-33.820080"; Longitude = "151.1850004"; OtherTransmissionAreaIds = "[11278,10747,10728,11503]"; TransmissionAreaId = 10728; }

so the TransmissionAreaId = 10728

appears ok, but if I test and use a decimal point ie: TransmissionAreaId = 10728.01

then i get the double quotes,

So how can i get rid of the double quotes??

Thanks a lot!

Whatever the value you display in NSLog , it displays the value as string. Its a nature of NSLog that it adds double-quotes( " ) around the values if they contain special characters other than alphanumeric values.

NSLog does this when it displays objects such as arrays and dictionaries. So, you won't see this behavior when you print just a string or float value directly in NSLog .

And, you have nothing to do with that than stop worrying!

Try using NSNumber to save your value for the key. Something like-

[dicto setObject:[NSNumber numberWithDouble:10723.01] forKey:@"TransmissionAreaId"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM