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); }
public ActionResult Settings(ControllerContext context) { string cfgPath = ServiceManager.Current.StorageRoot + @"\settings.xml"; JObject jdom = new JObject(); if (context.HttpContext.Request.HttpMethod.ToUpper().Equals("POST")) { foreach (DictionaryEntry parameters in context.HttpContext.Request.Form) { IParameter parameter = (IParameter)parameters.Value; if (!StringUtility.IsNullOrEmpty(parameter.Name) && !StringUtility.IsNullOrEmpty(parameter.Value)) ConfigManager.SetSetting(parameter.Name, parameter.Value); } ConfigManager.Save(cfgPath); } else { ConfigManager.Load(cfgPath); foreach (DictionaryEntry parameter in ConfigManager.GetSettings()) { jdom.Add(parameter.Key.ToString(), parameter.Value.ToString()); } } return JsonResult(jdom); }
/// <summary> /// Consume a JSON object /// </summary> /// <param name="ctx"></param> /// <param name="throws"></param> /// <returns></returns> private static JsonParserContext ConsumeObject( this JsonParserContext ctx, bool throws ) { if (ctx.ConsumeWhiteSpace().ConsumeAnyChar("{", throws).IsSucceeded) { var jctr = new JObject(); bool shouldThrow = false; do { ctx.Begin(); if (ctx.ConsumeString(shouldThrow).IsSucceeded) { var name = (string)(JValue)ctx.Result; ctx.ConsumeWhiteSpace() .ConsumeAnyChar(":", true) .ConsumeValue(true); jctr.Add(name, (JToken)ctx.Result); } shouldThrow = true; } while ((char)ctx.ConsumeWhiteSpace().ConsumeAnyChar(",}", true).Result == ','); ctx.SetResult(jctr); } return ctx; }
public ActionResult Info(ControllerContext context) { JObject jdom = new JObject(); jdom.Add("software", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); jdom.Add("version", SystemInfo.Version.ToString()); jdom.Add("oemString", SystemInfo.OEMString); jdom.Add("isEmulator", SystemInfo.IsEmulator.ToString()); jdom.Add("idModel", SystemInfo.SystemID.Model); jdom.Add("idOem", SystemInfo.SystemID.OEM); jdom.Add("idSku", SystemInfo.SystemID.SKU); jdom.Add("availableMemory", Debug.GC(false).ToString("n0") + " bytes"); jdom.Add("ipAddress", HttpService.Current.InterfaceAddress.ToString()); jdom.Add("ipPort", HttpService.Current.ServicePort); jdom.Add("hostname", ServiceManager.Current.ServerName); jdom.Add("dnsSuffix", ServiceManager.Current.DnsSuffix); jdom.Add("sntpEnabled", ServiceManager.Current.SntpEnabled); jdom.Add("dhcpEnabled", ServiceManager.Current.DhcpEnabled); jdom.Add("dnsEnabled", ServiceManager.Current.DnsEnabled); jdom.Add("httpEnabled", ServiceManager.Current.HttpEnabled); jdom.Add("loglevel", ServiceManager.Current.LogLevel.ToString()); return JsonResult(jdom); }