Question

How would I store data from a JSON Object from the Blockchain Exchange Rates API: https://blockchain.info/ticker into a NSString?

This is what I have so far:

NSURL *url = [NSURL URLWithString:@"https://blockchain.info/ticker"];
NSData *rate = [NSData dataWithContentsOfURL:url];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:rate options:kNilOptions error:nil];
NSLog(@"Data%@", [dic description]);

NSString *response = [dic valueForKey:@"USD"];
NSLog(@"Last: %@", response);

From the NSLog I get:

{
    15m = "656.01";
    last = "656.01";
    buy = "656.01"; 
    sell = "656.45";
    symbol = "$";
}

How do I get only the last value (store the number 656.01 by itself?

Was it helpful?

Solution

The response is a JSON dictionary, where the value for each entry is also a dictionary. The natural thing to do, then, is to turn it into an actual NSDictionary using NSJSONSerialization. Then you can do whatever you like with it -- you could store it as a property list for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top