Question

How do I go about parsing this https://coinbase.com/api/v1/prices/historical? into x (time) and y (price) arrays to create a line chart using core-plot (or other recommendations)? I'm up to here:

-(void)URL
{   
    dispatch_async(coinbaseQueue, ^{

        NSString* coinbaseURL= @"https://coinbase.com/api/v1/prices/historical?";
        NSData* data = [NSData dataWithContentsOfURL: [NSURL URLWithString:coinbaseURL]];
        if (data == nil)
        {
             NSLog(@"url: loading ERROR");
           [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(URL) userInfo:nil repeats:YES];//was NO

        }else
        {
            [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
        }
    });
}
- (void)fetchedData:(NSData *)responseData {
    //parse out the json data
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
                                                         options:kNilOptions
                                                           error:&error];
//parse
}

also any further help, links to tutorials for core-plot. much appreciated Thanks!

Was it helpful?

Solution

This is a very simple dataformat. From the result the link you posted returns I don't see any JSON involved. Retrieve the result as a simple string and use NSString's - (NSArray *)componentsSeparatedByString:(NSString *)separator to first separate lines (use the line break as separator string). Then for each line do the same but this time with comma as separator. This will give you an array with 2 entries for each line (a date and a price). Now convert both values to NSDate and NSNumber and store them in your x and y data arrays, respectively.

For How-Tos, tutorials etc. read coreplot's wiki.

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