[ad_1]
以下のjson構造を使用してc#でデータテーブルを設定するにはどうすればよいですか
{ "store": "Barnes Rd. C.S.C.", "storeID": 1001, "items": [ { "item": "1K AirteltiGO Scratch Card", "details": [ { "startSerial": "64235900000", "endSerial": "64235900000", "quantity": 1 } ] } ] }
私が試したこと:
try { var client = new HttpClient(); String jsonstring = null; int transno = Convert.ToInt32(lbltransactionnumbertovoid.Text); int storeid = Convert.ToInt32(Session["StoreID"]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); client.BaseAddress = new Uri(Constants.BaseApiAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync("url" + storeid + "/" + transno).Result; transdetails.Columns.Clear(); transdetails.Rows.Clear(); transdetails.Clear(); //Gridtransactionitemsprint.DataSource = transdetails; //Gridtransactionitemsprint.DataBind(); if (response.IsSuccessStatusCode) { jsonstring = response.Content.ReadAsStringAsync().Result; Root deserializedClass = JsonConvert.DeserializeObject<Root>(response.ToString()); transdetails = (DataTable)JsonConvert.DeserializeObject(jsonstring, (typeof(DataTable))); if (transdetails != null && transdetails.Rows.Count > 0) { //DataTable DT = new DataTable(); gridtransactionsoldserials.DataSource = transdetails; gridtransactionsoldserials.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#transactionsoldserials').modal('show');", true); } else { gridtransactionsoldserials.DataSource = transdetails; gridtransactionsoldserials.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), "HidePopup", "$('#transactionsoldserials').modal('hide')", true); } } else { gridtransactionsoldserials.DataSource = transdetails; gridtransactionsoldserials.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#transactionsoldserials').modal('show');", true); } } catch (Exception ex) { if (Session["username"] == null) { Response.Redirect("Login.aspx"); } else { Constants.writelog(Session["username"].ToString() + ":" + Session["StoreId"].ToString() + ":" + ex.Message.ToString() + ":" + "Invoice" + ":" + "Transactionitemserials()" + " " + "method was called"); lblmessages.Text = ex.Message.ToString(); ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#validations').modal('show');", true); } }
解決策 1
これは役立つかもしれません: リストを DataTable に変換する[^]
組み込みに対処するには、おそらく少し調整する必要があります details
クラスですが、それは大きな問題ではありません。
[ad_2]
コメント