public void BuildFromCode() { JsonObject json = new JsonObject(); json.AddMember("member1", "INIT"); json.AddMember("member2","foobar"); json.AddMember("member3"); JsonValue jv = json.GetValue ("member3"); jv.SetArray(); jv.array.PushBack(1); jv.array.PushBack(2); jv.array.PushBack(3); jv.array.PushBack(4); JsonObject jsonObj = new JsonObject(); jsonObj.AddMember("intv", 123); jsonObj.AddMember("srtv", "hoge"); jsonObj.AddMember("doublev", 123.456); json.AddMember("member4", jsonObj); Debug.Log (json.ToPrettyString ()); }
public void CastToWringType() { JsonObject json = new JsonObject(); json.AddMember("member1"); json["member1"].stringValue = "hello world"; Assert.Catch ( typeof(InvalidCastException), delegate { int v = (int)json["member1"]; } ); }
public void CastToString() { JsonObject json = new JsonObject(); json.AddMember("member1"); json["member1"].stringValue = "hello world"; Assert.That ( "hello world" == (string)json["member1"] ); }
public void PropertiesOrderTest() { JsonObject data = new JsonObject (); string json = "{\"first\":\"one\",\"second\":\"two\"," + "\"third\":\"three\",\"fourth\":\"four\"}"; data.AddMember("first", "one"); data.AddMember("second", "two"); data.AddMember("third", "three"); data.AddMember("fourth", "four"); Assert.AreEqual (json, data.ToString ()); }
public void NullValue() { string json = "{\"test\":null}"; JsonObject data = new JsonObject (); data.AddMember("test", (string)null); Assert.AreEqual (json, data.ToString ()); }
public void GetKeysTest() { JsonObject data = new JsonObject (); data.AddMember("first", "one"); data.AddMember("second", "two"); data.AddMember("third", "three"); data.AddMember("fourth", "four"); //Assert.AreEqual (4, data.Count, "A1"); //foreach (string k in data.Keys) // Assert.IsNotNull (data[k], "A2"); }
public void EqualsTest() { JsonObject o = new JsonObject(); o.AddMember("member"); JsonValue a = o["member"]; JsonValue b; // Compare ints a.intValue = 7; b = 7; Assert.IsTrue (a.Equals (b), "A1"); Assert.IsFalse (a.Equals (null), "A2"); b = 8; Assert.IsFalse (a.Equals (b), "A3"); // Compare longs a.longValue = 10L; b = 10L; Assert.IsTrue (a.Equals (b), "A4"); // Compare Long and Int (the same value) // NOTE: // The expected behaviour of LitJson for (10.Equals(10L)) is False // but Unity's Json will return True because that is more // expected result in natural manner b = 10; Assert.AreEqual (10L.Equals(10), a.Equals (b), "A5"); // Compare Long and Long (different value) b = 11L; Assert.IsFalse (a.Equals (b), "A6"); // Compare doubles a.doubleValue = 78.9; b = 78.9; Assert.IsTrue (a.Equals (b), "A7"); b = 78.899999; Assert.IsFalse (a.Equals (b), "A8"); // Compare booleans a.boolValue = true; b = true; Assert.IsTrue (a.Equals (b), "A9"); b.boolValue = false; Assert.IsFalse (a.Equals (b), "A10"); // Compare strings a.stringValue = "walrus"; b = "walrus"; Assert.IsTrue (a.Equals (b), "A11"); b = "Walrus"; Assert.IsFalse (a.Equals (b), "A12"); }
public void AsObjectTest() { JsonObject data = new JsonObject (); data.AddMember("alignment", "left"); //data["alignment"] = "left"; data.AddMember("font", new JsonObject()); data["font"].AddMember("name", "Arial"); data["font"].AddMember("style", "italic"); data["font"].AddMember("size", 10); data["font"].AddMember("color", "#fff"); Assert.IsTrue (data.isObject, "A1"); string json = @"{""alignment"":""left"",""font"":{""name"":""Arial"",""style"":""italic"",""size"":10,""color"":""#fff""}}"; //Debug.Log (data.ToString ()); Assert.AreEqual (json, data.ToString(), "A2"); }
public void ParseModifyAndToString() { JsonObject json = new JsonObject(); json.ParseDocument(testInput1); json.AddMember("category", "INIT"); json.AddMember("data_value","foobar"); JsonValue v = json["name1"]; json["name1"].SetString ("adsjlfajsdlfajsdflajs dsjfjdfajd."); json["name2"].SetDouble(345.678); Debug.Log (json.ToPrettyString ()); }