private IList <City> loadCities() { // In this case we're loading from local assets. // NOTE: could alternatively easily load from network System.IO.Stream stream; try { stream = Assets.open("cities.json"); } catch (IOException) { return(null); } // GSON can parse the data. // Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects. // To work around this, use the ExclusionStrategy below or downgrade to 1.7.1 // See more here: https://code.google.com/p/google-gson/issues/detail?id=440 Gson gson = (new GsonBuilder()).setExclusionStrategies(new ExclusionStrategyAnonymousInnerClassHelper(this)) .create(); JsonElement json = (new JsonParser()).parse(new System.IO.StreamReader(stream)); IList <City> cities = gson.fromJson(json, (new TypeTokenAnonymousInnerClassHelper(this)).Type); // Open a transaction to store items into the realm // Use copyToRealm() to convert the objects into proper RealmObjects managed by Realm. realm.beginTransaction(); ICollection <City> realmCities = realm.copyToRealm(cities); realm.commitTransaction(); return(new List <City>(realmCities)); }
protected internal virtual void onPostExecute(string jsonResponse) { Log.v(outerInstance.TAG, "onPostExecute:"); // Parse the JSON response, get the token and append it to the protected media url. // Then play add the video to the view and play it. Gson gson = new Gson(); ResourceAccessResponse response = gson.fromJson(jsonResponse, typeof(ResourceAccessResponse)); string url = Resources.getString([email protected]_media_url); Uri.Builder builder = Uri.parse(url).buildUpon(); builder.appendQueryParameter("hdnea", response.SecurityToken); url = builder.build().ToString(); brightcoveVideoView.add(Video.createVideo(url)); brightcoveVideoView.start(); }
protected internal virtual void onPostExecute(string jsonResponse) { Log.v(outerInstance.TAG, "onPostExecute:"); // Parse the JSON response, get the first IDP and pass it to the webview activity // to load the login page. IList <string> idps = new List <string>(); Gson gson = new Gson(); ChooserResponse response = gson.fromJson(jsonResponse, typeof(ChooserResponse)); IEnumerator it = response.PossibleIdps.SetOfKeyValuePairs().GetEnumerator(); while (it.hasNext()) { DictionaryEntry pairs = (DictionaryEntry)it.next(); idps.Add(pairs.Key.ToString()); it.remove(); } Intent intent = new Intent(outerInstance, typeof(WebViewActivity)); intent.putExtra(AIS_TARGET_URL, outerInstance.initUrl + idps[0]); startActivityForResult(intent, WEBVIEW_ACTIVITY); }
public String prettyJson(String json) { IDictionary<string, object> obj = gson.fromJson<Dictionary<string, object>>(json, typeof(Dictionary<string, object>)); return gson.toJson(obj); }