public IActionResult GetJson(ControllerContext context)
        {
            JArray jcar = new JArray();
            jcar.Add(new JProperty("make", "ford"));
            jcar.Add(new JProperty("model", "mustang"));
            jcar.Add(new JProperty("color", "blue"));

            JArray jcar1 = new JArray();
            jcar1.Add(new JProperty("make", "bmw"));
            jcar1.Add(new JProperty("model", "M5"));
            jcar1.Add(new JProperty("color", "black"));

            JArray jgroup = new JArray();
            jgroup.Add(new JProperty("group", "car"));
            jgroup.Add(new JProperty("type", jcar));
            jgroup.Add(new JProperty("type", jcar1));

            JArray jar = new JArray();
            jar.Add(new JProperty("style", ""));
            jar.Add(new JProperty("data-role", "update"));
            jar.Add(new JProperty("data-inset", "true"));
            jar.Add(new JProperty("group", jgroup));

            JObject jdom = new JObject();
            jdom.Add("date", new DateTime(1983, 3, 20).ToString());
            jdom.Add("data-role", "update");
            jdom.Add("style", jar);

            return JsonResult(jdom);
        }
Beispiel #2
0
        /// <summary>
        /// Consume a JSON array
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="throws"></param>
        /// <returns></returns>
        private static JsonParserContext ConsumeArray(
            this JsonParserContext ctx,
            bool throws
            )
        {
            if (ctx.ConsumeWhiteSpace().ConsumeAnyChar("[", throws).IsSucceeded)
            {
                var jctr = new JArray();
                bool shouldThrow = false;

                do
                {
                    ctx.Begin();
                    if (ctx.ConsumeValue(shouldThrow).IsSucceeded)
                        jctr.Add((JToken)ctx.Result);
                    shouldThrow = true;
                }
                while ((char)ctx.ConsumeWhiteSpace().ConsumeAnyChar(",]", true).Result == ',');

                ctx.SetResult(jctr);
            }

            return ctx;
        }