开发者

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 u开发者_StackOverflow中文版se 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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜