开发者

parsing a float from web-service with JSON

开发者 https://www.devze.com 2023-03-02 15:05 出处:网络
to parse a NSString i have used this : NSString *adress=[stations objectForKey:@\"adress_station\"]; what about a float, how should i call it, i try to do that :

to parse a NSString i have used this :

NSString *adress=[stations objectForKey:@"adress_station"];

what about a float, how should i call it, i try to do that :

       fl开发者_JAVA技巧oat distance=[stations objectForKey:@"distance"];

but i have got an error :

incompatible type in initialization

i don't want to put it in NSString, i need it as float because i need it in other operations :)


float distance = [[stations objectForKey:@"distance"] floatValue];

objectForKey returns an object (in this case I assume an NSString).

Calling -floatValue on an NSString will get the data as a float.

0

精彩评论

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