Saya mencoba memuat data dari https://www.quandl.com/api/ v3/datatables/WIKI.

Muncul dalam bentuk seperti di bawah ini

{"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}}.

Namun saya mencoba memuat di asp .net seperti di bawah ini tetapi mendapatkan kesalahan yang mengatakan tidak dapat menemukan data.

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/>";
            }
        }

    }
}

Sepertinya saya tidak tahu cara memuat data di bagian awal file json {"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]],

-1
John 121 15 November 2017, 15:10

1 menjawab

Jawaban Terbaik

Anda perlu memeriksa item data bukan item yang dapat didata

 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
Filip Cordas 15 November 2017, 12:35