private void TestArray(JsonArray ja) { var grade = ja.Get <JsonObject>(0); Assert.IsTrue(grade.Property <string>("subject") == "Math"); Assert.IsTrue(grade.Property <float>("grade") == 5f); grade = ja.Get <JsonObject>(1); Assert.IsTrue(grade.Property <string>("subject") == "English"); Assert.IsTrue(grade.Property <double>("grade") == 3.74); int number = ja.Get <int>(2); Assert.IsTrue(number == 5); double e = ja.Get <double>(3); Assert.IsTrue(e == 3140000000000); string xyz = ja.Get <string>(4); Assert.IsTrue(xyz == "xyz"); }
private static Boolean JsonEquals(Object obj1, Object obj2) { if (obj1 is JsonObject && obj2 is JsonObject) { JsonObject json1 = (JsonObject)obj1; JsonObject json2 = (JsonObject)obj2; IEnumerator json1Keys = json1.Keys(); while (json1Keys.MoveNext()) { string key = (string)json1Keys.Current; if (!json2.Has(key)) { return(false); } Object value1 = json1.Get(key); Object value2 = json2.Get(key); if (!JsonEquals(value1, value2)) { return(false); } } } else if (obj1 is JsonArray && obj2 is JsonArray) { JsonArray obj1Array = (JsonArray)obj1; JsonArray obj2Array = (JsonArray)obj2; if (obj1Array.Length() != obj2Array.Length()) { return(false); } for (int i = 0; i < obj1Array.Length(); i++) { Boolean matchFound = false; for (int j = 0; j < obj2Array.Length(); j++) { if (JsonEquals(obj1Array.Get(i), obj2Array.Get(j))) { matchFound = true; break; } } if (!matchFound) { return(false); } } } else { return(obj1.Equals(obj2)); } return(true); }
List <Girl> LoadGrid(JsonArray girls) { List <Girl> grid = new List <Girl>(); for (int i = 0; i < girls.Count; i++) { JsonObject data = girls.Get <JsonObject>(i); JsonArray seeds = data.Get <JsonArray>("seeds"); string id = seeds.ToString(); if (allGirls.ContainsKey(id)) { grid.Add(allGirls[id]); } else { string base64 = data.Get <string>("image"); Girl g = new Girl(seeds, base64); grid.Add(g); allGirls[id] = g; } } SaveGirls(); return(grid); }