public void ProcessRequest(HttpContext context) { context.Response.CacheControl = "no-cache"; context.Response.Expires = -1; context.Response.ContentType = "application/json"; JsonArray RootJsonArray = new JsonArray(); RootJsonArray.Add(new JsonObject(new string[] { "dataIndex", "type", "header", "width", "sortable", "hidden" }, new object[] { "Id", "int", "ID", 30, true, true })); RootJsonArray.Add(new JsonObject(new string[] { "id", "dataIndex", "type", "header", "width", "sortable" }, new object[] { "ColNameAutoExpand", "Name", "string", "Name", 180, true })); RootJsonArray.Add(new JsonObject(new string[] { "id", "dataIndex", "type", "header", "width", "sortable", "align" }, new object[] { "ColSalaryEdit", "Salary", "float", "Salary", 75, true, "center" })); RootJsonArray.Add(new JsonObject(new string[] { "id", "dataIndex", "type", "header", "width", "sortable", "align" }, new object[] { "ColBirthDateEdit", "BirthDate", "date", "BirthDate", 100, true, "center" })); RootJsonArray.Add(new JsonObject(new string[] { "id", "dataIndex", "type", "header", "width", "sortable", "align" }, new object[] { "ColCheckedEdit", "Checked", "boolean", "Checked", 50, true, "center" })); JsonTextWriter tmpJsonTextWriter = new JsonTextWriter(context.Response.Output); RootJsonArray.Export(tmpJsonTextWriter); tmpJsonTextWriter.Flush(); tmpJsonTextWriter.Close(); }
public void ProcessRequest(HttpContext context) { context.Response.CacheControl = "no-cache"; context.Response.Expires = -1; context.Response.ContentType = "application/json"; string cmd = context.Request.Form["cmd"]; if (cmd != null) { cmd = cmd.Trim().ToLower(); } else { cmd = string.Empty; } JsonObject JsonObject = null; JsonArray JsonArray = null; if (cmd == "load") { ulong RootId = 0UL; JsonObject tmpJsonObject = new JsonObject(new Dictionary <string, object> { { "id", RootId }, { "nodeID", RootId }, { "pnodeID", RootId }, { "text", "Select All" }, { "expanded", true } }); JsonArray Children; tmpJsonObject.Accumulate("leaf", (Children = GetChildren(GetTree(), null, 1)) == null); if (Children != null) { for (int i = 0; i < Children.Count; ++i) { ((JsonObject)Children[i])["pnodeID"] = RootId; } tmpJsonObject.Accumulate("children", Children); } JsonArray = new JsonArray(new JsonObject[] { tmpJsonObject }); } JsonTextWriter tmpJsonTextWriter = new JsonTextWriter(context.Response.Output); if (JsonObject != null) { JsonObject.Export(tmpJsonTextWriter); } if (JsonArray != null) { JsonArray.Export(tmpJsonTextWriter); } tmpJsonTextWriter.Flush(); tmpJsonTextWriter.Close(); }
static void Main(string[] args) { string FileName = "log.log"; if (File.Exists(FileName)) { File.Delete(FileName); } StreamWriter file = new StreamWriter(FileName, true, System.Text.Encoding.GetEncoding(1251)); JsonTextWriter tmpJsonTextWriter = new JsonTextWriter(file); JsonObject tmpJsonObject = null; JsonArray tmpJsonArray = null; #if TEST_TO_STRING tmpJsonObject = new JsonObject(new Dictionary <string, object> { { "FInt", 1 }, { "FFloatF", 1.3 }, { "FFloatD", 1.3m }, { "FDate", DateTime.Now.Date }, { "FDateTime", DateTime.Now.Date }, { "FString", "\"as'df\\/ghj'kl\"" }, { "FBoolean", true } }); Console.WriteLine(tmpJsonObject.ToString()); tmpJsonObject = null; Console.WriteLine(); tmpJsonArray = new JsonArray(new JsonArray[] { new JsonArray(new object[] { 1, 1.3, 1.3m, DateTime.Now.Date, DateTime.Now, "\"as'df\\/ghj'kl\"", true }), new JsonArray(new object[] { 1, 1.3, 1.3m, DateTime.Now.Date, DateTime.Now, "\"as'df\\/ghj'kl\"", true }), new JsonArray(new object[] { 1, 1.3, 1.3m, DateTime.Now.Date, DateTime.Now, "\"as'df\\/ghj'kl\"", true }) }); Console.WriteLine(tmpJsonArray.ToString()); tmpJsonArray = null; #endif #if TEST_TYPES tmpJsonObject = new JsonObject(); //tmpJsonObject = new JsonObject(new Dictionary<string, object> { { "LongValue", 13L }, { "ULongValue", 13UL } }); tmpJsonObject.Put("LongValue", 13L); tmpJsonObject.Put("ULongValue", 13UL); tmpJsonObject.Accumulate("EnumValueFirst", TestEnum.First); tmpJsonObject.Accumulate("EnumValueSecond", TestEnum.Second); tmpJsonObject.Accumulate("EnumValueFirstInt", (int)TestEnum.First); tmpJsonObject.Accumulate("EnumValueSecondInt", (int)TestEnum.Second); decimal? DecimalWithNull = null, DecimalWithValue = 13; tmpJsonObject.Accumulate("DecimalWithNull", DecimalWithNull); tmpJsonObject.Accumulate("DecimalWithValue", DecimalWithValue); tmpJsonObject.Accumulate("DBNullValue", DBNull.Value); #endif #if TEST_EMPTY_CONSTRUCTOR tmpJsonObject = new JsonObject(); tmpJsonObject.Accumulate("id", "id"); tmpJsonObject.Accumulate("text", "text"); JsonArray tmpJsonArray = new JsonArray(); for (int i = 0; i < 5; ++i) { JsonObject tmpTmpJsonObject = new JsonObject(); tmpTmpJsonObject.Accumulate("id", "id" + i); tmpTmpJsonObject.Accumulate("text", i); tmpTmpJsonObject.Accumulate("Today", DateTime.Today); tmpTmpJsonObject.Accumulate("Now", DateTime.Now); tmpJsonArray.Add(tmpTmpJsonObject); } tmpJsonObject.Accumulate("children", tmpJsonArray); #endif #if TEST_CONSTRUCTOR_DICTIONARY tmpJsonObject = new JsonObject(new Dictionary <string, object> { { "success", true }, { "errors", new JsonObject(new Dictionary <string, object> { { "title", "Sounds like a Chick Flick" } }) }, { "errormsg", "That movie title sounds like a chick flick." } }); #endif #if TEST_CONSTRUCTOR_STRING_OBJECT tmpJsonObject = new JsonObject(new string[] { "success", "errors", "errormsg" }, new object[] { true, new JsonObject(new string[] { "title" }, new object[] { "Sounds like a Chick Flick" }), "That movie title sounds like a chick flick." }); #endif #if TEST_CONSTRUCTOR_COLLECTION tmpJsonArray = new JsonArray(new object[] { "1st", "2nd", "3rd" }); #endif if (tmpJsonObject != null) { tmpJsonObject.Export(tmpJsonTextWriter); } if (tmpJsonArray != null) { tmpJsonArray.Export(tmpJsonTextWriter); } tmpJsonTextWriter.Flush(); tmpJsonTextWriter.Close(); file.Flush(); file.Close(); }
public void ProcessRequest(HttpContext context) { context.Response.CacheControl = "no-cache"; context.Response.Expires = -1; context.Response.ContentType = "application/json"; JsonObject JsonObject = null; JsonArray JsonArray = null; string xaction = context.Request.Form["xaction"]; if (xaction != null) { xaction = xaction.Trim().ToLower(); } else { xaction = string.Empty; } try { switch (xaction) { case "read": { JsonArray = new JsonArray(new int[] { 1, 3, 5 }); break; } case "update": { string[] selectedArray = context.Request.Form.GetValues("selected"), _selectedArray_; string selectedStr = context.Request.Form["selected"]; _selectedArray_ = selectedStr.Split(new char[] { ',' }); List <int> SelectedList = new List <int>(); for (int i = 0; i < selectedArray.Length; ++i) { int tmpInt; if (int.TryParse(selectedArray[i], out tmpInt)) { SelectedList.Add(tmpInt); } } JsonObject = new JsonObject(new Dictionary <string, object> { { "success", true } }); break; } default: { throw new Exception("Unknown xaction: \"" + xaction + "\""); } } } catch (Exception eException) { JsonObject = new JsonObject(new Dictionary <string, object> { { "success", false }, { "message", eException.Message } }); } JsonTextWriter tmpJsonTextWriter = new JsonTextWriter(context.Response.Output); if (JsonArray != null) { JsonArray.Export(tmpJsonTextWriter); } else if (JsonObject != null) { JsonObject.Export(tmpJsonTextWriter); } tmpJsonTextWriter.Flush(); tmpJsonTextWriter.Close(); }
public void ProcessRequest(HttpContext context) { string nodeStr = context.Request.Form["node"]; context.Response.ContentType = "application/json"; //context.Response.Write("[{\"text\" : \"Audi\", \"id\": 100, \"leaf\" : false, \"cls\" : \"folder\", \"children\" : [{\"text\" : \"A3\", \"id\": 1000, \"leaf\" : false, \"cls\" : \"folder\", \"children\" : [{\"text\" : \"Fuel Economy\", \"id\" : \"100000\", \"leaf\" : true, \"cls\" : \"file\"},{\"text\" : \"Invoice\", \"id\" : \"100001\", \"leaf\" : true, \"cls\" : \"file\"},{\"text\" : \"MSRP\", \"id\" : \"100002\", \"leaf\" : true, \"cls\" : \"file\"},{\"text\" : \"Options\", \"id\" : \"100003\", \"leaf\" : true, \"cls\" : \"file\"},{\"text\" : \"Specifications\", \"id\" : \"100004\", \"leaf\" : true, \"cls\" : \"file\"}]}]}, {\"text\" : \"BMW\", \"id\": 200, \"leaf\" : false, \"cls\" : \"folder\", \"children\" : []}]"); int node = 0; List <string> list = new List <string>(); bool HasChild = false; if (Int32.TryParse(nodeStr, out node)) { switch (node) { case 1: { list.Add("A3"); list.Add("A4"); list.Add("A6"); list.Add("A8"); HasChild = true; break; } case 2: { list.Add("M"); list.Add("M3"); list.Add("M5"); list.Add("M6"); HasChild = true; break; } default: { list.Add("Fuel Economy"); list.Add("Invoice"); list.Add("MSRP"); list.Add("Options"); list.Add("Specifications"); break; } } } else { list.Add("Audi"); list.Add("BMW"); HasChild = true; } JsonArray tmpJsonArraj = new JsonArray(); for (int i = 0; i < list.Count; ++i) { JsonObject tmpJsonObject = new JsonObject(); tmpJsonObject.Accumulate("id", node * 10 + i + 1); tmpJsonObject.Accumulate("text", list[i]); tmpJsonObject.Accumulate("leaf", !HasChild); tmpJsonObject.Accumulate("cls", HasChild ? "folder" : "file"); tmpJsonObject.Accumulate("checked", i == 1); tmpJsonArraj.Add(tmpJsonObject); } JsonTextWriter tmpJsonTextWriter = new JsonTextWriter(context.Response.Output); tmpJsonArraj.Export(tmpJsonTextWriter); context.Response.Flush(); context.Response.End(); }