Reputation: 2310
I'm creating a currency converter and using the Google Finance API to do so.
I'm following these simple instructions.
The URL outputs a page that looks something like this:
{lhs: "100 Euros",rhs: "132.240437 Australian dollars",error: "",icc: true}
My question is, what is the best way to extract the outputted value (132.240437) as a string?
Upvotes: 1
Views: 198
Reputation: 540
The simplest way is to use RegEx (e.g. RegexKit Lite). For this task you'll need:
[respStr stringByMatching:@".*rhs: \"([0-9\-\.]*)" capture:1L];
Upvotes: 1
Reputation: 80265
Get a simple JSON parser like this one. Then
#include "JSON.h"
After getting your JSON string called, say, download
from the API:
NSDictionary *currencyData = [download JSONValue];
NSString *numberString = [currencyData objectForKey:@"rhs"];
numberString = [[numberString componentsSeparatedByString:@" "] objectAtIndex:0];
Upvotes: 0