ios - How to convert NSArray object to double -


i'm retrieving value json in nsarray format. it's temperature.

however in celsius , wish convert kelvin. need add 274.15. i'm not able since it's nsarray , can't add directly.

i tried converting nsstring , converting double seems don't have option.

this current code:

nsdictionary *temp = [currentdate objectforkey:@"temp"];          nsarray* maxtemp = [temp objectforkey:@"max"];         nslog(@"max temp  : %@ kelvin",maxtemp );         nsarray* mintemp = [temp objectforkey:@"min"];         nslog(@"min temp  : %@ kelvin",mintemp); 

all wanna ( maxtemp + 274.15 )

current values in celsius:

max temp  : 28.8 kelvin min temp  : 26.55 kelvin 

since log statements displaying numeric values, can tell contents of dictionary "max" , "min" keys not arrays. strings. (json sends data strings.)

nsstring has method doublevalue. try this:

nsdictionary *temp = [currentdate objectforkey:@"temp"];  nsstring* maxtempstring = [temp objectforkey:@"max"]; double maxtemp = [maxtempstring doublevalue]; nslog(@"max temp  : %f kelvin", maxtemp );  nsstring* mintempstring = [temp objectforkey:@"min"]; double mintemp = [mintempstring doublevalue]; nslog(@"min temp  : %f kelvin", mintemp); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -