示例#1
0
        public void TryConvertJson_ArrayOfJsonObjectStrings()
        {
            string[] input = new string[]
            {
                "{ \"name\": \"Larry\" }",
                "{ \"name\": \"Moe\" }",
                "{ \"name\": \"Curly\" }"
            };

            object result     = null;
            bool   didConvert = NodeFunctionInvoker.TryConvertJson(input, out result);

            Assert.True(didConvert);

            object[] objects = result as object[];
            Dictionary <string, object> obj = (Dictionary <string, object>)objects[0];

            Assert.Equal("Larry", obj["name"]);

            obj = (Dictionary <string, object>)objects[1];
            Assert.Equal("Moe", obj["name"]);

            obj = (Dictionary <string, object>)objects[2];
            Assert.Equal("Curly", obj["name"]);
        }
        public void TryConvertJson_JsonObjectString()
        {
            JObject child = new JObject
            {
                { "Name", "Mary" },
                { "Location", "Seattle" },
                { "Age", 5 }
            };

            JObject parent = new JObject
            {
                { "Name", "Bob" },
                { "Location", "Seattle" },
                { "Age", 40 },
                { "Children", new JArray(child) }
            };

            object result;
            string input      = parent.ToString();
            bool   didConvert = NodeFunctionInvoker.TryConvertJson(input, out result);

            Assert.True(didConvert);

            var resultDictionary = (IDictionary <string, object>)result;
            var resultChildren   = (IEnumerable <object>)resultDictionary["Children"];
            var resultChild      = (IDictionary <string, object>)resultChildren.ElementAt(0);

            Assert.Equal(5, (long)resultChild["Age"]);
        }