public async Task TestToJsonStructure2Async() { LiteJsonStructureBuilder jsonStructureBuilder = new DotJsonMiniStructureBuilder(); object obj = new TestBean(33, "Maybe"); Object jsonObj = null; try { //var task = jsonStructureBuilder.BuildJsonStructureAsync(obj, -1); //// var task = jsonStructureBuilder.BuildJsonStructureAsync(obj); //// ???? //if (task.IsCompleted) { // jsonObj = task.Result; //} jsonObj = await jsonStructureBuilder.BuildJsonStructureAsync(obj, -1); } catch (DotJsonMiniException ex) { System.Diagnostics.Debug.WriteLine("Exception = " + ex.Message); } System.Diagnostics.Debug.WriteLine("jsonObj = " + jsonObj.ToDebugString <string, object>()); }
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); }