Exemplo n.º 1
0
        public void typeTest()
        {
            //Create a JSON object with all the types
            JSONObject json1 = new JSONObject("{id:1, \"name\": \"Chris Richards\", isTrue:true, isFalse:false, list:[true, false, null], object:{gum:\"Trident\", type:\"Spearmint\"}}");

            Assert.AreEqual(1, json1.intForKey("id"));
            Assert.AreEqual("Chris Richards", json1.stringForKey("name"));
            Assert.IsTrue(json1.boolForKey("isTrue"));
            Assert.IsFalse(json1.boolForKey("isFalse"));
            Assert.IsInstanceOf(typeof(System.Collections.Generic.List<object>), json1.listForKey("list"));
            Assert.IsInstanceOf<JSONObject>(json1.objectForKey("object"));

            System.Collections.Generic.List<object> list = json1.listForKey("list");
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(true, list[0]);
            Assert.AreEqual(false, list[1]);
            Assert.AreEqual(null, list[2]);

            JSONObject obj = json1.objectForKey("object");
            Assert.AreEqual("Trident", obj.stringForKey("gum"));
            Assert.AreEqual("Spearmint", obj.stringForKey("type"));
        }