Exemplo n.º 1
0
        private void J5_button_Click(object sender, EventArgs e)
        {
            Json_Org_textBox.Clear();
            List <string> ids = new List <string>()
            {
                "4", "8", "15", "16", "23", "42"
            };
            //string key = "score_update";

            LEVCommObject_test1 levobj = new LEVCommObject_test1();

            levobj.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            Dictionary <string, Object> idsList = new Dictionary <string, Object>();

            idsList.Add("idsList1", ids);
            idsList.Add("idsList2", ids);
            idsList.Add("idsList3", ids);
            idsList.Add("idsList4", levobj);
            //levobj.ParameterObjDict = idsList;
            //levobj.Obj = ids;
            /*序列化Dictionary物件*/
            //string jsonStr = JsonConvert.SerializeObject(levobj, Formatting.None);
            string jsonStr = JsonConvert.SerializeObject(idsList, Formatting.None);

            /*Formatting.Indented,這樣的字串輸出在瀏覽器上檢視的話有排版效果較易閱讀*/
            Json_Org_textBox.AppendText(jsonStr + Environment.NewLine);
        }
Exemplo n.º 2
0
        private void J3_button_Click(object sender, EventArgs e)
        {
            Json_Org_textBox.Clear();
            List <string> ids = new List <string>()
            {
                "4", "8", "15", "16", "23", "42"
            };
            //string key = "score_update";

            LEVCommObject levobj_child = new LEVCommObject();

            levobj_child.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj_child.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            levobj_child.Obj     = ids;

            LEVCommObject levobj_Parent = new LEVCommObject();

            levobj_Parent.ObjName = LEV_Comm_Obj_Type.LEV_B2B_App.ToString();
            levobj_Parent.ObjType = LEV_Comm_Obj_Type.LEV_B2B_App;
            levobj_Parent.Obj     = levobj_child;

            /*序列化Dictionary物件*/
            string jsonStr = JsonConvert.SerializeObject(levobj_Parent, Formatting.None);

            /*Formatting.Indented,這樣的字串輸出在瀏覽器上檢視的話有排版效果較易閱讀*/
            Json_Org_textBox.AppendText(jsonStr + Environment.NewLine);
        }
Exemplo n.º 3
0
        private void j9_button_Click(object sender, EventArgs e)
        {
            Json_Org_textBox.Clear();
            List <string> ids1 = new List <string>()
            {
                "14測試", "18", "215", "126", "223", "242"
            };
            List <string> ids = new List <string>()
            {
                "4", "8", "15", "16", "23", "42"
            };
            //string key = "score_update";

            LEVCommObject_test1 levobj = new LEVCommObject_test1();

            levobj.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            Dictionary <string, Object> idsList = new Dictionary <string, Object>();

            idsList.Add("c:/idsList.1", ids);
            idsList.Add("c:/idsList.2", ids1);
            idsList.Add("c:/idsList.3", ids);
            levobj.ParameterObjDict = idsList;

            Dictionary <string, string> idsStr = new Dictionary <string, string>();

            idsStr.Add("idsStr1", "t1測試");
            idsStr.Add("idsStr2", "t2測試");
            idsStr.Add("idsStr3", "t3測試");
            levobj.ParameterStrDict = idsStr;

            LEVCommObject_test1 levobj_c = new LEVCommObject_test1();

            levobj_c.ObjName          = LEV_Comm_Obj_Type.LEV_Charger_Check_App.ToString();
            levobj_c.ObjType          = LEV_Comm_Obj_Type.LEV_Charger_Check_App;
            levobj_c.ParameterStrDict = idsStr;
            levobj.extendParameterObj = levobj_c;

            /*Bson序列化物件*/
            var            memoryStream = new MemoryStream();
            BsonWriter     bsonWriter   = new BsonWriter(memoryStream);
            JsonSerializer serializer   = new JsonSerializer();

            serializer.Serialize(bsonWriter, levobj);
            //var res = string.Format(BitConverter.ToString(memoryStream.ToArray()));
            byte[] bsonData = memoryStream.ToArray();
            var    res      = string.Format(BitConverter.ToString(bsonData));

            //var res = BitConverter.ToString(bsonData);
            Json_Org_textBox.AppendText(res + Environment.NewLine);
        }
Exemplo n.º 4
0
        private void Json_1_button_Click(object sender, EventArgs e)
        {
            Json_Org_textBox.Clear();
            Dictionary <string, int> original = new Dictionary <string, int>();

            original.Add("A", 1);
            original.Add("B", 2);
            /*序列化Dictionary物件*/
            string jsonStr = JsonConvert.SerializeObject(original, Formatting.None);

            /*Formatting.Indented,這樣的字串輸出在瀏覽器上檢視的話有排版效果較易閱讀*/
            //Json_Org_textBox.AppendText("Dictionary物件經過序列化:" + jsonStr + Environment.NewLine);
            Json_Org_textBox.AppendText(jsonStr + Environment.NewLine);
        }
Exemplo n.º 5
0
        private void J7_1_button_Click(object sender, EventArgs e)
        {
            Json_Org_textBox.Clear();
            List <string> ids1 = new List <string>()
            {
                "14測試", "18", "215", "126", "223", "242"
            };
            List <string> ids = new List <string>()
            {
                "4", "8", "15", "16", "23", "42"
            };
            //string key = "score_update";

            LEVCommObject_J7_1 levobj = new LEVCommObject_J7_1();

            levobj.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            Dictionary <string, Object> idsList = new Dictionary <string, Object>();

            idsList.Add("c:/idsList.1", ids);
            idsList.Add("c:/idsList.2", ids1);
            idsList.Add("c:/idsList.3", ids);
            levobj.ParameterObjDict = idsList;

            Dictionary <string, string> idsStr = new Dictionary <string, string>();

            idsStr.Add("idsStr1", "t1測試");
            idsStr.Add("idsStr2", "t2測試");
            idsStr.Add("idsStr3", "t3測試");
            levobj.ParameterStrDict = idsStr;

            LEVCommObject_J7_1 levobj_c = new LEVCommObject_J7_1();

            levobj_c.ObjName          = LEV_Comm_Obj_Type.LEV_Charger_Check_App.ToString();
            levobj_c.ObjType          = LEV_Comm_Obj_Type.LEV_Charger_Check_App;
            levobj_c.ParameterStrDict = idsStr;
            levobj.extendParameterObj = levobj_c;
            /*序列化物件*/
            string jsonStr = JsonConvert.SerializeObject(levobj, Formatting.None);
            int    len     = jsonStr.Length;

            byte[] byteData = Encoding.UTF8.GetBytes(jsonStr);
            string s        = Encoding.UTF8.GetString(byteData, 0, byteData.Length);

            //string jsonStr = JsonConvert.SerializeObject(levobj, Formatting.Indented);
            /*Formatting.Indented,這樣的字串輸出在瀏覽器上檢視的話有排版效果較易閱讀*/
            Json_Org_textBox.AppendText(jsonStr + Environment.NewLine);
        }
Exemplo n.º 6
0
        private void b13_button_Click(object sender, EventArgs e)
        {
            //string imageFile = Path.Combine(Environment.CurrentDirectory, "pic.png");
            string imageFile = Path.Combine(Environment.CurrentDirectory, "small.jpg");

            //Read file to byte array
            FileStream stream = File.OpenRead(imageFile);

            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, fileBytes.Length);
            stream.Close();

            Json_Org_textBox.Clear();
            /*create 物件*/
            LEVCommObject_test2 levobj = new LEVCommObject_test2();

            levobj.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            Dictionary <string, string> imageStr = new Dictionary <string, string>();

            imageStr.Add("image", "image圖片測試");
            levobj.ParameterImageDict = imageStr;
            Dictionary <string, byte[]> imageBody = new Dictionary <string, byte[]>();

            imageBody.Add("image", fileBytes);
            levobj.ParameterImageBodyDict = imageBody;

            /*Bson序列化物件*/
            var            memoryStream = new MemoryStream();
            BsonWriter     bsonWriter   = new BsonWriter(memoryStream);
            JsonSerializer serializer   = new JsonSerializer();

            serializer.Serialize(bsonWriter, levobj);
            //var res = string.Format(BitConverter.ToString(memoryStream.ToArray()));
            byte[] bsonData = memoryStream.ToArray();
            var    res      = string.Format(BitConverter.ToString(bsonData));

            Json_Org_textBox.AppendText(res + Environment.NewLine);
        }
Exemplo n.º 7
0
        private void j11_button_Click(object sender, EventArgs e)
        {
            //string imageFile = Path.Combine(Environment.CurrentDirectory, "pic.png");
            string imageFile = Path.Combine(Environment.CurrentDirectory, "small.jpg");

            //Read file to byte array
            FileStream stream = File.OpenRead(imageFile);

            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, fileBytes.Length);
            stream.Close();

            Json_Org_textBox.Clear();
            /*create 物件*/
            LEVCommObject_test2 levobj = new LEVCommObject_test2();

            levobj.ObjName = LEV_Comm_Obj_Type.LEV_B2C_App.ToString();
            levobj.ObjType = LEV_Comm_Obj_Type.LEV_B2C_App;
            Dictionary <string, string> imageStr = new Dictionary <string, string>();

            imageStr.Add("image", "image圖片測試");
            levobj.ParameterImageDict = imageStr;
            Dictionary <string, byte[]> imageBody = new Dictionary <string, byte[]>();

            imageBody.Add("image", fileBytes);
            levobj.ParameterImageBodyDict = imageBody;
            /*序列化物件*/
            string jsonStr = JsonConvert.SerializeObject(levobj, Formatting.None);
            /*Formatting.Indented,這樣的字串輸出在瀏覽器上檢視的話有排版效果較易閱讀*/
            //string jsonStr = JsonConvert.SerializeObject(levobj, Formatting.Indented);
            int len = jsonStr.Length;

            byte[] byteData = Encoding.UTF8.GetBytes(jsonStr);
            string s        = Encoding.UTF8.GetString(byteData, 0, byteData.Length);

            Json_Org_textBox.AppendText(jsonStr + Environment.NewLine);
        }