2017-11-15 7 views
-1

https://www.quandl.com/api/v3/datatables/WIKIからデータをロードしようとしています。私は以下のようなASP .NETでのロードが、それはデータを見つけることができないというエラーを取得しようしかしJSONソースをc#ASP .NET出力に変換する

{"datatable":{"data":[["A","2017-11-14",66.98,67.8,66.89,67.46,1682158.0,0.0,1.0,66.98,67.8,66.89,67.46,1682158.0]],"columns":[{"name":"ticker","type":"String"},{"name":"date","type":"Date"},{"name":"open","type":"BigDecimal(34,12)"},{"name":"high","type":"BigDecimal(34,12)"},{"name":"low","type":"BigDecimal(34,12)"},{"name":"close","type":"BigDecimal(34,12)"},{"name":"volume","type":"BigDecimal(37,15)"},{"name":"ex-dividend","type":"BigDecimal(42,20)"},{"name":"split_ratio","type":"double"},{"name":"adj_open","type":"BigDecimal(50,28)"},{"name":"adj_high","type":"BigDecimal(50,28)"},{"name":"adj_low","type":"BigDecimal(50,28)"},{"name":"adj_close","type":"BigDecimal(50,28)"},{"name":"adj_volume","type":"double"}]},"meta":{"next_cursor_id":null}}. 

以下のような形で出てきます。

public partial class _Default : System.Web.UI.Page 
{ 
    protected string url = "https://www.quandl.com/api/v3/datatables/WIKI/PRICES?date=2017-11-14&ticker=A&api_key=<YOURAPIKEY>"; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     //create an instance of HttpClient 
     HttpClient client = new HttpClient(); 

     //DefaultRequestHeader to Json 
     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

     //Create an instance of HttpResponse & invoke the service asynchronously 
     HttpResponseMessage response = client.GetAsync(url).Result; 

     //Http Status code 200 
     if (response.IsSuccessStatusCode) 
     { 
      //Read response content result into string variable 
      string JSON = response.Content.ReadAsStringAsync().Result; 

      //Deserialize the string(JSON) object 
      var jObj = (JObject)JsonConvert.DeserializeObject(JSON); 

      //access items from anonymous (Json object) type and add to the list 
      var result = jObj["datatable"].Select(item => new 
      { 
       key = item["data"][0], 
       code = item["data"][1], 
       description = item["data"][2], 
       buy = item["data"][3], 
       sell = item["data"][4], 
      }).ToList(); 

      //output the data || NOTE: **NSERT into database table** 
      foreach (var item in result) 
      { 
       lblOutput.Text = item.key + "--" + item.code + "--" + item.description + item.buy + item.sell + "<br/>"; 
      } 
     } 

    } 
} 

私は、JSONファイル {「データテーブル」の開始ビットにデータをロードする方法を見つけ出すように見えることはできません: "、[[「A」2017-11-:{「データ」あなたはデータ項目の上に行く必要がある14" 、66.98,67.8,66.89,67.46,1682158.0,0.0,1.0,66.98,67.8,66.89,67.46,1682158.0]]、

+0

現在のところ、「あなたは1日に50通の匿名ユーザー制限を超えています。」* – derloopkat

答えて

0

ないDataTableのアイテム

var result = jObj["datatable"]["data"].Select(item => new 
       { 
        key = item[0], 
        code = item[1], 
        description = item[2], 
        buy = item[3], 
        sell = item[4], 
       }).ToList(); 
+0

すばらしく働いています。ありがとう:) –

+0

@ John121私はまだ公開情報ではなく秘密にする必要があります質問のAPIキーを削除することをお勧めします。 –

+0

Ok削除済みAPIキーありがとう –

関連する問題