Trying To Use This JSON In GridView. But Tried Every Sample On Internet But "Sequence contains no elements"
Some Time Other Errors Come. Please Help Me Read This JSON Into GridView By JSON URL.
{
"-MtmDfxQyVwkr7SkHsrg": {
"amount": "500000",
"branch_num": "001",
"machineID": "VB12213C20156",
"shift": 1,
"userID": "4245",
"voucher_date": "2022-01-19T15:05:46",
"voucher_number": "156202200001"
},
"-MtmE1Y54t3G_wLTuICr": {
"amount": "50000",
"branch_num": "001",
"machineID": "VB12213C20156",
"shift": 1,
"userID": "4245",
"voucher_date": "2022-01-19T15:07:22",
"voucher_number": "156202200002"
}
}
This Json Is Showing In DataList, But I Don't Want To Show In DataList. I Want To Show In GridView.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
namespace _5M_Solution
{
public partial class Harqat_Maqbozat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetJsonData();
}
}
[System.Web.Services.WebMethod]
public void GetJsonData()
{
System.Web.UI.HtmlControls.HtmlGenericControl li = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Page.Master.FindControl("Main_lnkmnu_Harqat_Maqbozat");
li.Attributes.Add("class", "menu single-menu active");
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
string json = (new WebClient()).DownloadString("https://receipt-voucher-default-rtdb.firebaseio.com/receipts.json");
Dictionary<string, object> values = JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, object>>(json);
object[] arr = new object[values.Count];
int i = 0;
foreach (var entry in values)
{
arr[i] = entry.Value;
i++;
}
dl_JsonDetails.DataSource = arr;
dl_JsonDetails.DataBind();
}
}
}