parsing a float from web-service with JSON
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.
精彩评论