public void SetContent(string jsonContent) { Type me = GetType(); JsonTextReader reader = new JsonTextReader(new System.IO.StringReader(jsonContent)); while (!reader.EOF) { object obj = reader.DeserializeNext(); JObject jobj = obj as JObject; JArray jlevel = obj as JArray; JArray jlevels = null; if (jobj != null) { if (!jobj.Contains("Fields")) { continue; } jlevel = (jobj["Fields"]) as JArray; if (jobj.Contains("Levels")) { jlevels = (jobj["Levels"]) as JArray; } } System.Globalization.CultureInfo Culture = GxContext.Current.localUtil.CultureInfo; SetContent(Culture, GetName(), me, this, jlevel, jlevels); break; } }
private JObject GetGXStateTokens(string state) { try { if (!string.IsNullOrEmpty(state)) { if (Preferences.UseBase64ViewState()) { state = Encoding.UTF8.GetString(Convert.FromBase64String(state)); } JsonReader reader = new JsonTextReader(new StringReader(state)); JsonToken token = reader.ReadToken(); if (token == JsonToken.Object) { return((JObject)reader.DeserializeNext()); } } } catch (Exception e) { GXLogging.Debug(log, "Error parsing GXState"); GXLogging.Debug(log, e.ToString()); GXLogging.Debug(log, state); } return(null); }
public static List <Geospatial> GetLocationGeography(String address) { String urlString = MAPS_URI + "geocode/json?address=" + GXUtil.UrlEncode(address) + "&sensor=false"; String ApiKey = ""; if (Config.GetValueOf("GoogleApiKey", out ApiKey)) { urlString += "&key=" + ApiKey; } String response = GXGeolocation.GetContentFromURL(urlString); List <Geospatial> result = new List <Geospatial>(); try { if (!string.IsNullOrEmpty(response)) { StringReader sr = new StringReader(response); JsonTextReader tr = new JsonTextReader(sr); JObject json = (JObject)(tr.DeserializeNext()); if (json.Contains("results")) { JArray results = (JArray)json["results"]; for (int i = 0; i < results.Length; i++) { JObject jo = (JObject)results[i]; if (jo.Contains("geometry")) { JObject geometry = (JObject)jo["geometry"]; if (geometry.Contains("location")) { JObject location = (JObject)geometry["location"]; if (location != null && (location.Contains("lat")) && (location.Contains("lng"))) { Geospatial point = new Geospatial(Convert.ToDecimal(location["lat"]), Convert.ToDecimal(location["lng"])); result.Add(point); } } } } } } } catch (JsonException ex) { GXLogging.Error(log, "getLocation error json:" + response, ex); } return(result); }
public static List <string> GetAddress(String location) { String urlString = MAPS_URI + "geocode/json?latlng=" + GXUtil.UrlEncode(location) + "&sensor=false"; String ApiKey = ""; if (Config.GetValueOf("GoogleApiKey", out ApiKey)) { urlString += "&key=" + ApiKey; } String response = GXGeolocation.GetContentFromURL(urlString); List <string> result = new List <string>(); try { if (!string.IsNullOrEmpty(response)) { StringReader sr = new StringReader(response); JsonTextReader tr = new JsonTextReader(sr); JObject json = (JObject)(tr.DeserializeNext()); if (json.Contains("results")) { JArray results = (JArray)json["results"]; for (int i = 0; i < results.Length; i++) { JObject jo = (JObject)results[i]; if (jo.Contains("formatted_address")) { result.Add((string)jo["formatted_address"]); } } } } } catch (JsonException ex) { GXLogging.Error(log, "getAddress error json:" + response, ex); } return(result); }
internal override T ReadJSON <T>(string json) { Jayrock.Json.JsonTextReader reader = new JsonTextReader(new StringReader(json)); return((T)reader.DeserializeNext()); }