Я получаю исключение nul reference при извлечении данных из сервиса arcgis и отображении их в сетке данных преобразование в json в datatable
I am getting nul reference exception while fetching data from arcgis service and showing them into a data grid converting into json to datatable
Я получаю исключение null reference в этой строке:
foreach (var features in results.features)результат.функции, показывающие ноль, но значение приходит в результатах. вот мой код ниже.
Что я уже пробовал:
public static string GISSERVER = ConfigurationManager.AppSettings["GISSERVER"].ToString(); protected void Page_Load(object sender, EventArgs e) { } private void BindDummyRow() { DataTable dummy = new DataTable(); dummy.Columns.Add("VILLAGE"); dummy.Columns.Add("TEHSIL"); dummy.Columns.Add("DISTRICT"); dummy.Columns.Add("STATE"); dummy.Rows.Add(); gvEmg.DataSource = dummy; gvEmg.DataBind(); } [WebMethod] public static string GetData() { string url = ""; DataTable dt = new DataTable(); dt.Columns.Add("VILLAGE", typeof(System.String)); dt.Columns.Add("STATE", typeof(System.String)); dt.Columns.Add("DISTRICT", typeof(System.String)); dt.Columns.Add("TEHSIL", typeof(System.String)); var client = new RestClient(GISSERVER);//"http://example.com"); // client.Authenticator = new HttpBasicAuthenticator(username, password); var request = new RestRequest(url, Method.GET); request.AddParameter("Where", "OBJECTID>0"); // adds to POST or URL querystring based on Method request.AddParameter("geometryType", "esriGeometryEnvelope"); request.AddParameter("spatialRel", "esriSpatialRelIntersects"); request.AddParameter("outFields", "STATE,DISTRICT,TEHSIL,VILLAGE"); request.AddParameter("returnGeometry", "false"); request.AddParameter("returnIdsOnly", "false"); request.AddParameter("returnCountOnly", "false"); request.AddParameter("returnZ", "false"); request.AddParameter("returnM", "false"); request.AddParameter("returnDistinctValues", "false"); request.AddParameter("f", "pjson"); RestResponse response = (RestResponse)client.Execute(request); var content = response.Content; // raw content as string var results = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(content); //JObject jalbum = results.results[0].value.features[0] as JObject; //var total = results.features.length(); foreach (var features in results.features) { var village1 = (string)features.attributes["VILLAGE"]; var state1 = (string)features.attributes["STATE"]; var dstrict1 = (string)features.attributes["DISTRICT"]; var Taluk1 = (string)features.attributes["TEHSIL"]; var village2 = village1.Trim(); var state2 = state1.Trim(); var dstrict2 = dstrict1.Trim(); var Taluk2 = Taluk1.Trim(); if (village2 == "" || state2 == "" || dstrict2 == "" || Taluk2 == "") { } else { DataRow dr = dt.NewRow(); dr["VILLAGE"] = village1; dr["STATE"] = state1; dr["DISTRICT"] = dstrict1; dr["TALUK"] = Taluk1; dt.Rows.Add(dr); } } DataSet ds = new DataSet(); ds.Merge(dt); return ds.GetXml(); }