Search code examples
iphoneiosjsonipadyahoo-finance

JSON Yahoo Finance Chart Data iOS Parse


I am currently trying to create a stock chart for NASDAQ, Dow Jones, and S&P 500. I cannot find any API (within reasonable pricing) to create this so I have been dabbling with the Yahoo Finance Chart API. It currently supports JSON, CSV, and XML. The performance is less than ideal when parsing XML or CSV so I would like to use the JSON response but I am running into issues. The JSON response does not actually return valid JSON. Does anyone have any insight on how to parse this in iOS or have an alternative suggestion?

Here is the JSON URL: http://chartapi.finance.yahoo.com/instrument/1.1/%5EIXIC/chartdata;type=close;range=1d/json/


Solution

  • Update:

    Indeed, the response is malformed as well. I tried the URL with a different ticker symbol and it looks like there is a stray " mark in the output in the previous_close field. If you remove the stray " mark, it should validate properly.

    "meta" :
     {
      "uri" :"/instrument/1.1/ITW/chartdata;type=close;range=1d/json/?callback=",
      "ticker" : "itw",
      "unit" : "MIN",
      "timezone" : "EST",
      "currency" : "USD",
      "gmtoffset" : -18000,
      "previous_close" : 62.9000"
     }
    

    ~

    Original:

    The response returned is in JSONP format.

    finance_charts_json_callback( {
    ...
    } )
    

    Off the cuff, you should be able to strip away finance_charts_json_callback( from the start and the trailing ) from the end and end up with valid JSON data.

    JSONP @ Wikipedia