public async Task TestJsonBuild1Async() { LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); IDictionary <String, Object> map = new Dictionary <String, Object>(); IList <Object> list1 = new List <Object>(); list1.Add("x"); list1.Add("y"); list1.Add("z"); map.Add("a", list1); map.Add("b", false); IDictionary <String, Object> map2 = new Dictionary <String, Object>(); map2.Add("p", 100); map2.Add("q", null); map2.Add("r", 200); map.Add("c", map2); Object obj = map; // String jsonStr = jsonBuilder.Build(obj, 2); String jsonStr = null; try { //var task = jsonBuilder.BuildAsync(obj); //// ???? //// if (task.IsCompleted) { // jsonStr = task.Result; //// } jsonStr = await jsonBuilder.BuildAsync(obj); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[1] jsonStr = " + jsonStr); }
public async Task TestParseStringAsync() { LiteJsonParser jsonParser = new DotJsonMiniParser(); // var jsonString = "{\"a\":[33, 55, 77]}"; var jsonString = "[300, {\"a\":[33, false, true], \"b\":null}, \"ft\\/st/lt\\/gt\", null]"; object node = null; try { //var task = jsonParser.ParseAsync(jsonString); //if (task.IsCompleted) { // node = task.Result; //} node = await jsonParser.ParseAsync(jsonString); System.Diagnostics.Debug.WriteLine("node = " + node); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } // format the jsonStr LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); // string jsonStr = jsonBuilder.build(node); string jsonStr = null; try { //var task = jsonBuilder.BuildAsync(node); //// task.RunSynchronously(); //jsonStr = task.Result; jsonStr = await jsonBuilder.BuildAsync(node); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("--------------------------------------------------------"); System.Diagnostics.Debug.WriteLine("jsonStr = " + jsonStr); int jsonLen = jsonStr.Length; System.Diagnostics.Debug.WriteLine("jsonLen = " + jsonLen); }
public async Task TestJsonBuild2Async() { LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); List <Object> list = new List <Object>(); list.Add("a"); Object obj = list; String jsonStr = null; try { //var task = jsonBuilder.BuildAsync(obj); //// ???? //// if (task.IsCompleted) { //jsonStr = task.Result; //// } jsonStr = await jsonBuilder.BuildAsync(obj); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[2] jsonStr = " + jsonStr); }
public async Task TestJsonBuild4Async() { LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); object obj = new { k1 = 123, k2 = "value" }; String jsonStr = null; try { //var task = jsonBuilder.BuildAsync(obj); //// ???? //if (task.IsCompleted) { // jsonStr = task.Result; //} jsonStr = await jsonBuilder.BuildAsync(obj); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[4] jsonStr = " + jsonStr); }
public async Task TestToJsonStructure1Async() { LiteJsonStructureBuilder jsonStructureBuilder = new DotJsonMiniStructureBuilder(); IDictionary <String, Object> map = new Dictionary <String, Object>(); IList <Object> list1 = new List <Object>(); list1.Add("x"); list1.Add("y\ny\ty\ry\\y ___ \\/ / ___ </ ___ y/y\"\u0033\u0035y\u001ay"); list1.Add("z"); list1.Add(null); map.Add("a", list1); //TestJsonCompatibleObject jb1 = new TestJsonCompatibleObject(); //map.Add("a2", jb1); //TestJsonCompatibleArray jb2 = new TestJsonCompatibleArray(); //map.Add("a3", jb2); map.Add("b", false); IDictionary <String, Object> map2 = new Dictionary <String, Object>(); map2.Add("p", 100); map2.Add("q", null); map2.Add("r", 200); map2.Add("s", Byte.MaxValue); map2.Add("t", new Byte[] {}); map2.Add("u", new Byte[] { Byte.MinValue }); map.Add("b2", null); map.Add("c", map2); map.Add("c2", map2); //TestBean bean1 = new TestBean(3, "aaaa"); //bean1.setAttrF(new char[]{'h','i'}); //IDictionary<String,Object> mapC1 = new Dictionary<String,Object>(); //mapC1.Add("ii", 33); //TestBean beanC1 = new TestBean(4, "bbbb"); //TestBean beanC2 = new TestBean(5, "cccc"); //mapC1.Add("ii22", new Object[]{1,2,3, beanC2}); //TestBean beanD3 = new TestBean(6, "dddd"); //IList<Object> listD3 = new List<Object> {1,2,3, beanD3}; //beanC2.setAttrD(listD3); //beanC1.setAttrE(beanC2); //beanC1.setAttrF(new char[]{'k','q','p'}); //mapC1.Add("jj", beanC1); //bean1.setAttrC(mapC1); //map.Add("d", bean1); //map.Add("z", new Object[]{ bean1 , beanC1} ); Object obj = map; Object jsonObj = null; try { //var task = jsonStructureBuilder.BuildJsonStructureAsync(obj, -1); //// var task = jsonStructureBuilder.BuildJsonStructureAsync(obj); //jsonObj = task.Result; jsonObj = await jsonStructureBuilder.BuildJsonStructureAsync(obj, -1); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } // if(jsonObj instanceof String) { // System.Diagnostics.Debug.WriteLine("jsonObj is String."); // } else { // System.Diagnostics.Debug.WriteLine("jsonObj is not a String."); // } //string objStr = null; //if (jsonObj != null) { // var dictObj = jsonObj as IDictionary<string, object>; // if (dictObj != null) { // objStr = dictObj.ToDebugString(); // } else { // var listObj = jsonObj as IList<object>; // if (listObj != null) { // objStr = listObj.ToDebugString<string, object>(); // } else { // objStr = jsonObj.ToString(); // } // } //} //System.Diagnostics.Debug.WriteLine("jsonObj = " + objStr); System.Diagnostics.Debug.WriteLine("jsonObj = " + jsonObj.ToDebugString <string, object>()); // For tracing LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); String jsonStr = null; try { //var task = jsonBuilder.BuildAsync(jsonObj); //// task.RunSynchronously(); // ???? //jsonStr = task.Result; jsonStr = await jsonBuilder.BuildAsync(jsonObj); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3] jsonStr = " + jsonStr); }
public async Task TestJsonBuild3Async() { LiteJsonBuilder jsonBuilder = new DotJsonMiniBuilder(); Object objA = new char[] { 'X', 'Y', 'Z' }; String jsonStrA = null; try { //var task = jsonBuilder.BuildAsync(objA); //// ???? //// if (task.IsCompleted) { // jsonStrA = task.Result; //// } jsonStrA = await jsonBuilder.BuildAsync(objA); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3A] jsonStrA = " + jsonStrA); Object objB = new byte[] { 3, 5, 7 }; String jsonStrB = null; try { //var task = jsonBuilder.BuildAsync(objB); //// ???? //// if (task.IsCompleted) { // jsonStrB = task.Result; //// } jsonStrB = await jsonBuilder.BuildAsync(objB); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3B] jsonStrB = " + jsonStrB); Object objC = new int[] { 101, -55, 25 }; String jsonStrC = null; try { //var task = jsonBuilder.BuildAsync(objC); //// ???? //// if (task.IsCompleted) { //jsonStrC = task.Result; //// } jsonStrC = await jsonBuilder.BuildAsync(objC); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3C] jsonStrC = " + jsonStrC); Object objD = new string[] { "abc", "pqr", "xyz" }; String jsonStrD = null; try { //var task = jsonBuilder.BuildAsync(objD); //// ???? //// if (task.IsCompleted) { //jsonStrD = task.Result; //// } jsonStrD = await jsonBuilder.BuildAsync(objD); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3D] jsonStrD = " + jsonStrD); Object objE = new object[] { "abc", new object[] { 5, new List <object>() { 33, "pp" }, new Dictionary <string, object>() { { "strArray", new object[] { 'a', 'b' } }, { "date", new DateTime() } } } }; String jsonStrE = null; try { //var task = jsonBuilder.BuildAsync(objE); //// ???? //// if (task.IsCompleted) { //jsonStrE = task.Result; //// } jsonStrE = await jsonBuilder.BuildAsync(objE); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("[3E] jsonStrE = " + jsonStrE); }