예제 #1
0
파일: test.cs 프로젝트: ripter/JSONObject
        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"));
        }