[英]ios double quotes on dictionary when decimal point added
Im interacting with JSON, for "get" it works ok, 我正在与JSON交互,如果要进行“获取”就可以了,
But with the "post", I have an error as the dictionary objects are surrounded with double quotes "" 但是对于“ post”,我有一个错误,因为字典对象被双引号“”包围
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, 对于Web服务,双引号出现错误,问题是,如果我使用点表示小数点,则会出现双引号,
NSMutableDictionary *dicto = [[NSMutableDictionary alloc]init]; 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"; 2011-10-10 17:28:47.265 MySwitch [14632:707]字典{纬度=“ -33.820080”; Longitude = "151.1850004"; 经度=“ 151.1850004”; OtherTransmissionAreaIds = "[11278,10747,10728,11503]"; OtherTransmissionAreaIds =“ [11278,10747,10728,11503]”; TransmissionAreaId = 10728; TransmissionAreaId = 10728; } }
so the TransmissionAreaId = 10728
所以TransmissionAreaId = 10728
appears ok, but if I test and use a decimal point ie: TransmissionAreaId = 10728.01
看起来还可以,但是如果我测试并使用小数点,即: 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. 无论您在NSLog中显示什么值,它都会将该值显示为字符串。 Its a nature of NSLog that it adds double-quotes( "
) around the values if they contain special characters other than alphanumeric values. NSLog的本质是,如果值包含字母数字值以外的特殊字符,则会在值周围添加双引号( "
)。
NSLog does this when it displays objects such as arrays and dictionaries. NSLog在显示诸如数组和字典之类的对象时会执行此操作。 So, you won't see this behavior when you print just a string or float value directly in NSLog . 因此,直接在NSLog中仅打印字符串或浮点值时,您将不会看到此行为。
And, you have nothing to do with that than stop worrying! 而且,与此无关,您别担心!
Try using NSNumber
to save your value for the key. 尝试使用NSNumber
保存键的值。 Something like- 就像是-
[dicto setObject:[NSNumber numberWithDouble:10723.01] forKey:@"TransmissionAreaId"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.