internal static List<Fixture> GetFixtures(int teamId, bool forceRefresh = false) { var content = GetUpcomingFixturesForTeam(teamId, forceRefresh); if (content == null) return null; var jsonArray = new JSONArray(content); return ConvertJsonArrayToFixtureList(jsonArray); }
public static void SerializeSystemBoolean(bool[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(obj); } }
/// <summary> /// adds the entry output data to the intent to be sent to a plugin /// </summary> public static void AddEntryToIntent(Intent intent, PwEntryOutput entry) { /*//add the entry XML not yet implemented. What to do with attachments? MemoryStream memStream = new MemoryStream(); KdbxFile.WriteEntries(memStream, new[] {entry}); string entryData = StrUtil.Utf8.GetString(memStream.ToArray()); intent.PutExtra(Strings.ExtraEntryData, entryData); */ //add the output string array (placeholders replaced taking into account the db context) Dictionary<string, string> outputFields = entry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); JSONObject jsonOutput = new JSONObject(outputFields); var jsonOutputStr = jsonOutput.ToString(); intent.PutExtra(Strings.ExtraEntryOutputData, jsonOutputStr); JSONArray jsonProtectedFields = new JSONArray( (System.Collections.ICollection)entry.OutputStrings .Where(pair => pair.Value.IsProtected) .Select(pair => pair.Key) .ToArray()); intent.PutExtra(Strings.ExtraProtectedFieldsList, jsonProtectedFields.ToString()); intent.PutExtra(Strings.ExtraEntryId, entry.Uuid.ToHexString()); }
// throws Exception public int getNumberOfAvailableUpdates() { string jsonStr = new RestClient().getMethod(server, "/patches.json"); JSONArray updates = new JSONArray(jsonStr); return updates.Length(); }
JSONArray GetDataSource() { JSONArray array = new JSONArray (); array.Put(getJsonObject("Alabama", "Vegetables", 9 )); array.Put(getJsonObject( "Alaska", "Vegetables", 3 )); array.Put(getJsonObject( "Arizona", "Rice", 11 )); array.Put(getJsonObject( "Arkansas", "Vegetables", 6 )); array.Put(getJsonObject( "California", "Rice", 55 )); array.Put(getJsonObject( "Colorado", "Rice", 9 )); array.Put(getJsonObject( "Connecticut", "Grains", 7 )); array.Put(getJsonObject( "Delaware", "Grains", 3 )); array.Put(getJsonObject( "District of Columbia", "Grains", 3 )); array.Put(getJsonObject( "Florida", "Rice", 29 )); array.Put(getJsonObject( "Georgia", "Rice", 16 )); array.Put(getJsonObject( "Hawaii", "Grains", 4 )); array.Put(getJsonObject( "Idaho", "Grains", 4 )); array.Put(getJsonObject( "Illinois", "Vegetables", 20 )); array.Put(getJsonObject( "Indiana", "Grains", 11 )); array.Put(getJsonObject( "Iowa", "Vegetables", 6 )); array.Put(getJsonObject( "Kansas", "Rice", 6 )); array.Put(getJsonObject( "Kentucky", "Grains", 8 )); array.Put(getJsonObject( "Louisiana", "Rice", 8 )); array.Put(getJsonObject( "Maine", "Grains", 4 )); array.Put(getJsonObject( "Maryland", "Grains", 10 )); array.Put(getJsonObject( "Massachusetts", "Grains", 11 )); array.Put(getJsonObject( "Michigan", "Grains", 16 )); array.Put(getJsonObject( "Minnesota", "Wheat", 10 )); array.Put(getJsonObject( "Mississippi", "Vegetables", 6 )); array.Put(getJsonObject( "Missouri", "Vegetables", 10 )); array.Put(getJsonObject( "Montana", "Grains", 3 )); array.Put(getJsonObject( "Nebraska", "Rice", 5 )); array.Put(getJsonObject( "Nevada", "Wheat", 6 )); array.Put(getJsonObject( "New Hampshire", "Grains", 4 )); array.Put(getJsonObject( "New Jersey", "Vegetables", 14 )); array.Put(getJsonObject( "New Mexico", "Rice", 5 )); array.Put(getJsonObject( "New York", "Vegetables", 29 )); array.Put(getJsonObject( "North Carolina", "Rice", 15 )); array.Put(getJsonObject( "North Dakota", "Grains", 3 )); array.Put(getJsonObject( "Ohio", "Vegetables", 18 )); array.Put(getJsonObject( "Oklahoma", "Rice", 7 )); array.Put(getJsonObject( "Oregon", "Wheat", 7 )); array.Put(getJsonObject( "Pennsylvania", "Vegetables", 20 )); array.Put(getJsonObject( "Rhode Island", "Grains", 4 )); array.Put(getJsonObject( "South Carolina", "Rice", 9 )); array.Put(getJsonObject( "South Dakota", "Grains", 3 )); array.Put(getJsonObject( "Tennessee", "Vegetables", 11 )); array.Put(getJsonObject( "Texas", "Vegetables", 38 )); array.Put(getJsonObject( "Utah", "Rice", 6 )); array.Put(getJsonObject( "Vermont", "Grains", 3 )); array.Put(getJsonObject( "Virginia", "Rice", 13 )); array.Put(getJsonObject( "Washington", "Vegetables", 12 )); array.Put(getJsonObject( "West Virginia", "Grains", 5 )); array.Put(getJsonObject( "Wisconsin", "Grains", 10 )); array.Put(getJsonObject( "Wyoming", "Wheat", 3 )); return array; }
public JSONArray GetDataSource() { var array = new JSONArray (); array.Put(new JSONObject().Put("Country","Brazil").Put("Population",204436000).Put("ShortName","BRA")); array.Put(new JSONObject().Put("Country","United States").Put("Population",321174000).Put("ShortName","USA")); array.Put(new JSONObject().Put("Country","Russia").Put("Population",146267288).Put("ShortName","RUS")); array.Put(new JSONObject().Put("Country","India").Put("Population",1272470000).Put("ShortName","IND")); array.Put(new JSONObject().Put("Country","China").Put("Population",1370320000).Put("ShortName","CHI")); array.Put(new JSONObject().Put("Country","Indonesia").Put("Population",255461700).Put("ShortName","INO")); return array; }
private static List<Fixture> ConvertJsonArrayToFixtureList(JSONArray jsonArray) { var list = new List<Fixture>(); var length = jsonArray.Length(); for (var i = 0; i < length; i++) { var jsonObject = jsonArray.OptJSONObject(i); if (jsonObject == null) continue; var fixture = new Fixture { AwayTeam = jsonObject.GetString("awayTeam"), HomeTeam = jsonObject.GetString("homeTeam"), Date = DateHelper.ParseUtcDate(jsonObject.GetString("date")) }; list.Add(fixture); } return list; }
public static string ToJsonString(this byte[] objs) { //TODO: byte array is a special one, convert to base64? var array = new JSONArray(); foreach (var obj in objs) { array.Put((int)obj); } return array.ToString(); }
// Encrypt the receipts and save them to file. void ToCache(IList<Receipt> receipts) { OuyaFacade.Log("Caching receipts"); var json = new JSONObject(); var array = new JSONArray(); foreach (var receipt in receipts) { var r = new JSONObject(); r.Put("identifier", receipt.Identifier); r.Put("priceInCents", receipt.PriceInCents); r.Put("purchaseDate", receipt.PurchaseDate.ToGMTString()); r.Put("generatedDate", receipt.GeneratedDate.ToGMTString()); r.Put("gamerUuid", receipt.Gamer); r.Put("uuid", receipt.Uuid); array.Put(r); } json.Accumulate("receipts", array); var text = json.ToString(); var encryptedReceipts = CryptoHelper.Encrypt(text, _gamerUuid); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var writer = new StreamWriter(store.OpenFile(receiptsFileName, FileMode.OpenOrCreate))) { writer.Write(encryptedReceipts); } } }
public static void SerializeSystemDecimal(decimal[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(obj); } }
private List<Song> MapSongs(string ret) { var arr = new JSONArray(ret); var list = new List<Song>(); for (var i = 0; i < arr.Length(); i++) { var item = (JSONObject)arr.Get(i); var id = item.GetInt("id"); var name = item.GetString("name"); var relativePath = item.GetString("relativePath"); var artist = item.GetString("artist"); var lenght = this.JsonToTimeSpan(item.GetJSONObject("length")); var lastModified = DateTime.Parse(item.GetString("lastModified")); var fileLenght = item.GetInt("fileLength"); var song = new Song(id, name, relativePath, artist, lenght, lastModified, fileLenght); list.Add(song); } return list; }
public static byte[] DeserializeSystemByteArray(JSONArray jsonArray) { var result = new byte[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (byte)jsonArray.OptInt(i); } return result; }
public static char[] DeserializeSystemCharArray(JSONArray jsonArray) { var result = new char[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = jsonArray.OptString(i)[0]; } return result; }
public static string ToJsonString(this TimeSpan[] objs) { var array = new JSONArray(); foreach (var obj in objs) { array.Put(JsonConvert.ToString(obj)); } return array.ToString(); }
public static Guid[] DeserializeSystemGuidArray(JSONArray jsonArray) { var result = new Guid[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = new Guid(jsonArray.OptString(i)); } return result; }
public static void SerializeSystemGuid(Guid[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(obj.ToString()); } }
public static void SerializeSystemDateTime(DateTime[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(JsonConvert.ToString(obj)); } }
public static double[] DeserializeSystemDoubleArray(JSONArray jsonArray) { var result = new double[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = jsonArray.OptDouble(i); } return result; }
public static void SerializeSystemDouble(double[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(obj); } }
public static decimal[] DeserializeSystemDecimalArray(JSONArray jsonArray) { var result = new decimal[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (decimal)jsonArray.OptLong(i); } return result; }
public static string ToJsonString(this short[] objs) { var array = new JSONArray(); foreach (var obj in objs) { array.Put((long)obj); } return array.ToString(); }
public static string ToJsonString(this float[] objs) { var array = new JSONArray(); foreach (var obj in objs) { array.Put((double)obj); } return array.ToString(); }
public static void SerializeSystemInt16(short[] objs, JSONArray jsonArray) { foreach (var obj in objs) { jsonArray.Put(obj); } }
public static string ToJsonString(this ulong[] objs) { var array = new JSONArray(); foreach (var obj in objs) { array.Put(obj.ToString()); } return array.ToString(); }
private Weather CallbackResponse(string responseObj) { Weather weather = null; Org.Json.JSONObject weatherMain = new Org.Json.JSONObject(responseObj); Org.Json.JSONArray weatherArray = new Org.Json.JSONArray(); weatherArray.Put(weatherMain); for (int i = 0; i < weatherArray.Length(); i++) { try { Org.Json.JSONObject weatherObject = weatherArray.GetJSONObject(i); JSONObject objectLocation = weatherObject.GetJSONObject("location"); JSONObject objectCurrent = weatherObject.GetJSONObject("current"); //JSONObject objectrequest = objectCurrent.GetJSONObject("request"); //"request":{ "type":"City","query":"Tel Aviv-Yafo, Israel","language":"en","unit":"m"} weather = new Weather(); weather.setTemperature(objectCurrent.GetString("temperature")); weather.setDescription(objectCurrent.GetString("weather_descriptions")); weather.setWind_kph(objectCurrent.GetString("wind_speed")); string icon = objectCurrent.GetString("weather_icons"); icon = icon.Replace("[\"" + "https:\\/\\/assets", @"https://assets"); icon = icon.Replace("[", ""); icon = icon.Replace("]", ""); icon = icon.Replace("\"", ""); icon = icon.Replace(@"\/", "//"); icon = icon.Replace(@"\\", "//"); //Android.Net.Uri uri = Android.Net.Uri.Parse(icon); //Android.Net.Uri uri = Android.Net.Uri.Parse(icon); //icon = uri.Path; //icon = uri.AbsolutePath; weather.setPoster(icon); weather.setIs_day(objectCurrent.GetString("is_day").ToString()); weather.setCloud(objectCurrent.GetString("cloudcover")); weather.setLast_update(objectLocation.GetString("localtime")); weather.setCountry(objectLocation.GetString("country")); icon = objectLocation.GetString("name").Trim(); icon = icon.Replace(@"[", ""); icon = icon.Replace("[", ""); icon = icon.Replace(@"]", ""); icon = icon.Replace("]", ""); icon = icon.Replace("\"", ""); icon = icon.Replace("\"", ""); icon = icon.Replace("[\"", ""); //icon = icon.Replace('\'', (char)32); weather.setCity(icon.Trim()); // "type":"City","query":"Tel Aviv-Yafo, Israel" weather.setRegion(objectLocation.GetString("region")); weather.setLocal_time(objectLocation.GetString("localtime")); weather.setTz_id(objectLocation.GetString("timezone_id")); //"localtime_epoch":1583177400,"utc_offset":"2.0" //wind_degree":311,"wind_dir":"NW","pressure":1021,"precip":0,"humidity":60,"cloudcover":7,"feelslike":17 try { //weather.setImageView(Utils.GetImageViewFromhUrl(weather.getPoster())); //weather.setImageView(new ImageView(Application.Context)); //Android.Net.Uri uri = Android.Net.Uri.Parse(weather.getPoster()); //weather.getImageView().SetImageURI(uri); } catch { } if (WeatherList.Count < 4) { WeatherList.Add(weather); } else { WeatherList[currentListIndex] = weather; } } catch (JSONException ex) { MH_Utils.Utils.WriteToLog(ex.Message); //Log.d("Error: ", ex.getMessage()); //ex.printStackTrace(); } } return(weather); }
private void ChangeLogLevel(string result) { var jsonArray = new JSONArray(result); var jsonObject = jsonArray.GetJSONObject(0); var logLevelString = jsonObject.Get("level").ToString(); var logLevel = LogLevel.FromString(logLevelString); var toEnable = (bool)jsonObject.Get("enable"); SetLogLevel(logLevel, toEnable); var message = string.Format("Set logging level to {0}", logLevelString); // _logger.Info(message); }
/// <exception cref="System.Exception"></exception> public virtual void TestRemoteConflictResolution() { // Create a document with two conflicting edits. Document doc = database.CreateDocument(); SavedRevision rev1 = doc.CreateRevision().Save(); SavedRevision rev2a = CreateRevisionWithRandomProps(rev1, false); SavedRevision rev2b = CreateRevisionWithRandomProps(rev1, true); // make sure we can query the db to get the conflict Query allDocsQuery = database.CreateAllDocumentsQuery(); allDocsQuery.SetAllDocsMode(Query.AllDocsMode.OnlyConflicts); QueryEnumerator rows = allDocsQuery.Run(); bool foundDoc = false; NUnit.Framework.Assert.AreEqual(1, rows.GetCount()); for (IEnumerator<QueryRow> it = rows; it.HasNext(); ) { QueryRow row = it.Next(); if (row.GetDocument().GetId().Equals(doc.GetId())) { foundDoc = true; } } NUnit.Framework.Assert.IsTrue(foundDoc); // Push the conflicts to the remote DB. Replication push = database.CreatePushReplication(GetReplicationURL()); RunReplication(push); NUnit.Framework.Assert.IsNull(push.GetLastError()); // Prepare a bulk docs request to resolve the conflict remotely. First, advance rev 2a. JSONObject rev3aBody = new JSONObject(); rev3aBody.Put("_id", doc.GetId()); rev3aBody.Put("_rev", rev2a.GetId()); // Then, delete rev 2b. JSONObject rev3bBody = new JSONObject(); rev3bBody.Put("_id", doc.GetId()); rev3bBody.Put("_rev", rev2b.GetId()); rev3bBody.Put("_deleted", true); // Combine into one _bulk_docs request. JSONObject requestBody = new JSONObject(); requestBody.Put("docs", new JSONArray(Arrays.AsList(rev3aBody, rev3bBody))); // Make the _bulk_docs request. HttpClient client = new DefaultHttpClient(); string bulkDocsUrl = GetReplicationURL().ToExternalForm() + "/_bulk_docs"; HttpPost request = new HttpPost(bulkDocsUrl); request.SetHeader("Content-Type", "application/json"); string json = requestBody.ToString(); request.SetEntity(new StringEntity(json)); HttpResponse response = client.Execute(request); // Check the response to make sure everything worked as it should. NUnit.Framework.Assert.AreEqual(201, response.GetStatusLine().GetStatusCode()); string rawResponse = IOUtils.ToString(response.GetEntity().GetContent()); JSONArray resultArray = new JSONArray(rawResponse); NUnit.Framework.Assert.AreEqual(2, resultArray.Length()); for (int i = 0; i < resultArray.Length(); i++) { NUnit.Framework.Assert.IsTrue(((JSONObject)resultArray.Get(i)).IsNull("error")); } WorkaroundSyncGatewayRaceCondition(); // Pull the remote changes. Replication pull = database.CreatePullReplication(GetReplicationURL()); RunReplication(pull); NUnit.Framework.Assert.IsNull(pull.GetLastError()); // Make sure the conflict was resolved locally. NUnit.Framework.Assert.AreEqual(1, doc.GetConflictingRevisions().Count); }
[Inline] //enum support protected static void AddToJsonArray(JSONArray jsonArray, long obj) { jsonArray.Put(obj); }
// Encrypt the receipts and save them to file. static void ToCache(IList<Receipt> receipts, string gamerUuid) { OuyaFacade.Log("Caching receipts"); var json = new JSONObject(); var array = new JSONArray(); foreach (var receipt in receipts) { var r = new JSONObject(); r.Put("identifier", receipt.Identifier); // PriceInCents is now deprecated. Use LocalPrice and CurrencyCode instead. // Retain field for compatibility. r.Put("priceInCents", 0); r.Put("purchaseDate", receipt.PurchaseDate.ToGMTString()); r.Put("generatedDate", receipt.GeneratedDate.ToGMTString()); r.Put("gamerUuid", receipt.Gamer); r.Put("uuid", receipt.Uuid); r.Put("localPrice", receipt.LocalPrice); r.Put("currencyCode", receipt.Currency); array.Put(r); } json.Accumulate("receipts", array); var text = json.ToString(); var encryptedReceipts = CryptoHelper.Encrypt(text, gamerUuid); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var writer = new StreamWriter(store.OpenFile(receiptsFileName, FileMode.OpenOrCreate))) { writer.Write(encryptedReceipts); } } }
public static short[] DeserializeSystemInt16Array(JSONArray jsonArray) { var result = new short[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = (short)jsonArray.OptInt(i); } return result; }
public static DateTime[] DeserializeSystemDateTimeArray(JSONArray jsonArray) { var result = new DateTime[jsonArray.Length()]; for (var i = 0; i < result.Length; i++) { result[i] = JsonConvert.ToDateTime(jsonArray.OptString(i)); } return result; }