Ejemplo n.º 1
0
        private void J8_1_button_Click(object sender, EventArgs e)
        {
            /*JSON字串反序列化為LEVCommObject_test1物件*/
            LEVCommObject_J7_1_chang back = JsonConvert.DeserializeObject <LEVCommObject_J7_1_chang>(Json_Org_textBox.Text);

            Json_Parse_textBox.AppendText("back : ObjName = " + back.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back : ObjType = " + back.ObjType + Environment.NewLine);
            Json_Parse_textBox.AppendText("back : ObjName more = " + back.ObjName_more + Environment.NewLine);
            Json_Parse_textBox.AppendText("back : ObjInt = " + back.ObjInt + Environment.NewLine);


            /*轉換,原為LEVCommObject_test1: Dictionary<string, Object>物件*/
            JObject jobj = JObject.FromObject(back.ParameterObjDict);
            Dictionary <string, object> values = jobj.ToObject <Dictionary <string, object> >();

            foreach (var item in values)
            {
                Json_Parse_textBox.AppendText("dict =>" + item + Environment.NewLine);
            }
            if (values.ContainsKey("c:/idsList.2"))
            {
                Json_Parse_textBox.AppendText("dict content =>" + values["c:/idsList.2"] + Environment.NewLine);
                List <string> sList = jobj["c:/idsList.2"].ToObject <List <string> >();
                foreach (string s in sList)
                {
                    Json_Parse_textBox.AppendText("=>" + s + Environment.NewLine);
                }
            }

            /*轉換,原為LEVCommObject_test1: Dictionary<string, string>物件*/
            jobj = JObject.FromObject(back.ParameterStrDict);
            Dictionary <string, string> val = jobj.ToObject <Dictionary <string, string> >();

            foreach (var s in val)
            {
                Json_Parse_textBox.AppendText("dict =>" + s + Environment.NewLine);
            }

            /*轉換,原為LEVCommObject_test1: Object extendParameterOb物件, set 為LEVCommObject_test1 Type*/
            jobj = JObject.FromObject(back.extendParameterObj);
            LEVCommObject_J7_1_chang levC_Obj = jobj.ToObject <LEVCommObject_J7_1_chang>();

            Json_Parse_textBox.AppendText("back child : ObjName = " + levC_Obj.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back child: ObjType = " + levC_Obj.ObjType + Environment.NewLine);
            /*轉換,原為LEVCommObject_test1: Dictionary<string, string>物件*/
            jobj = JObject.FromObject(levC_Obj.ParameterStrDict);
            Dictionary <string, string> levC_val = jobj.ToObject <Dictionary <string, string> >();

            foreach (var s in levC_val)
            {
                Json_Parse_textBox.AppendText("dict =>" + s + Environment.NewLine);
            }
            Json_Parse_textBox.AppendText("test =>" + levC_Obj.ObjName_more + Environment.NewLine);
            Json_Parse_textBox.AppendText("test =>" + levC_Obj.extendParameterObj1 + Environment.NewLine);
            /*轉換,原為LEVCommObject_test1: Version 物件*/
            jobj = JObject.FromObject(levC_Obj.ver);
            Version ver = jobj.ToObject <Version>();

            Json_Parse_textBox.AppendText("version =>" + ver + Environment.NewLine);
        }
Ejemplo n.º 2
0
        private void j12_button_Click(object sender, EventArgs e)
        {
            /*JSON字串反序列化為LEVCommObject_test2物件*/
            LEVCommObject_test2 back = JsonConvert.DeserializeObject <LEVCommObject_test2>(Json_Org_textBox.Text);

            Json_Parse_textBox.AppendText("back : ObjName = " + back.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back : ObjType = " + back.ObjType + Environment.NewLine);

            /*轉換,原為LEVCommObject_test2: Dictionary<string, string>物件*/
            JObject jobj = JObject.FromObject(back.ParameterImageDict);
            Dictionary <string, string> val = jobj.ToObject <Dictionary <string, string> >();

            foreach (var s in val)
            {
                Json_Parse_textBox.AppendText("image dict =>" + s + Environment.NewLine);
            }
            /*轉換,原為LEVCommObject_test2: Dictionary<string, byte[]>物件*/
            jobj = JObject.FromObject(back.ParameterImageBodyDict);
            Dictionary <string, byte[]> values = jobj.ToObject <Dictionary <string, byte[]> >();

            byte[] body = new byte[] { 0 };
            if (values.ContainsKey("image"))
            {
                body = jobj["image"].ToObject <byte[]>();
            }

            //Begins the process of writing the byte array back to a file
            //string imageFile = Path.Combine(Environment.CurrentDirectory, "pic_test.png");
            string imageFile = Path.Combine(Environment.CurrentDirectory, "small_test.jpg");

            using (Stream file = File.OpenWrite(imageFile))
            {
                file.Write(body, 0, body.Length);
            }
        }
Ejemplo n.º 3
0
        private void J6_button_Click(object sender, EventArgs e)
        {
            JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full
            };
            /*JSON字串反序列化為Dictionary物件*/
            Dictionary <string, Object> back_L1 = JsonConvert.DeserializeObject <Dictionary <string, Object> >(Json_Org_textBox.Text);

            foreach (string key in back_L1.Keys)
            {
                Json_Parse_textBox.AppendText(key + "=>" + back_L1[key] + Environment.NewLine);
            }

            JArray        a    = JArray.FromObject(back_L1["idsList3"]);
            List <string> list = new List <string>();

            foreach (var item in a)
            {
                list.Add((string)item);
            }
            LEVCommObject_test1 back_L2 = JsonConvert.DeserializeObject <LEVCommObject_test1>(back_L1["idsList4"].ToString());

            JObject jobj     = JObject.FromObject(back_L1["idsList4"]);
            JToken  ageToken = jobj["ObjName"];
        }
Ejemplo n.º 4
0
        private void j10_button_Click(object sender, EventArgs e)
        {
            /*BSON字串反序列化為LEVCommObject_test1物件*/
            var                 memoryStream = new MemoryStream(StringToBytes(Json_Org_textBox.Text));
            BsonReader          reader       = new BsonReader(memoryStream);
            JsonSerializer      serializer   = new JsonSerializer();
            LEVCommObject_test1 back         = serializer.Deserialize <LEVCommObject_test1>(reader);

            //LEVCommObject_test1 back = JsonConvert.DeserializeObject<LEVCommObject_test1>(Json_Org_textBox.Text);
            Json_Parse_textBox.AppendText("back : ObjName = " + back.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back : ObjType = " + back.ObjType + Environment.NewLine);


            /*轉換,原為LEVCommObject_test1: Dictionary<string, Object>物件*/
            JObject jobj = JObject.FromObject(back.ParameterObjDict);
            Dictionary <string, object> values = jobj.ToObject <Dictionary <string, object> >();

            foreach (var item in values)
            {
                Json_Parse_textBox.AppendText("dict =>" + item + Environment.NewLine);
            }
            if (values.ContainsKey("c:/idsList.2"))
            {
                Json_Parse_textBox.AppendText("dict content =>" + values["c:/idsList.2"] + Environment.NewLine);
                List <string> sList = jobj["c:/idsList.2"].ToObject <List <string> >();
                foreach (string s in sList)
                {
                    Json_Parse_textBox.AppendText("=>" + s + Environment.NewLine);
                }
            }

            /*轉換,原為LEVCommObject_test1: Dictionary<string, string>物件*/
            jobj = JObject.FromObject(back.ParameterStrDict);
            Dictionary <string, string> val = jobj.ToObject <Dictionary <string, string> >();

            foreach (var s in val)
            {
                Json_Parse_textBox.AppendText("dict =>" + s + Environment.NewLine);
            }

            /*轉換,原為LEVCommObject_test1: Object extendParameterOb物件, set 為LEVCommObject_test1 Type*/
            jobj = JObject.FromObject(back.extendParameterObj);
            LEVCommObject_test1 levC_Obj = jobj.ToObject <LEVCommObject_test1>();

            Json_Parse_textBox.AppendText("back child : ObjName = " + levC_Obj.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back child: ObjType = " + levC_Obj.ObjType + Environment.NewLine);
            /*轉換,原為LEVCommObject_test1: Dictionary<string, string>物件*/
            jobj = JObject.FromObject(levC_Obj.ParameterStrDict);
            Dictionary <string, string> levC_val = jobj.ToObject <Dictionary <string, string> >();

            foreach (var s in levC_val)
            {
                Json_Parse_textBox.AppendText("dict =>" + s + Environment.NewLine);
            }
        }
Ejemplo n.º 5
0
        private void Json_2_button_Click(object sender, EventArgs e)
        {
            /*JSON字串反序列化為Dictionary物件*/
            //Dictionary<string, int> back = (Dictionary<string, int>)JsonConvert.DeserializeObject(Json_Org_textBox.Text, typeof(Dictionary<string, int>));
            Dictionary <string, int> back = JsonConvert.DeserializeObject <Dictionary <string, int> >(Json_Org_textBox.Text);

            foreach (string key in back.Keys)
            {
                Json_Parse_textBox.AppendText(key + "=>" + back[key] + Environment.NewLine);
            }
        }
Ejemplo n.º 6
0
        private void J4_button_Click(object sender, EventArgs e)
        {
            /*JSON字串反序列化為Dictionary物件*/
            LEVCommObject back_L1 = (LEVCommObject)JsonConvert.DeserializeObject(Json_Org_textBox.Text, typeof(LEVCommObject));

            Json_Parse_textBox.AppendText("back_L1 : ObjName = " + back_L1.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back_L1 : ObjType = " + back_L1.ObjType + Environment.NewLine);
            string backArrayStr = back_L1.Obj.ToString();

            LEVCommObject back_L2 = (LEVCommObject)JsonConvert.DeserializeObject(backArrayStr, typeof(LEVCommObject));

            Json_Parse_textBox.AppendText("back_L2 : ObjName = " + back_L2.ObjName + Environment.NewLine);
            Json_Parse_textBox.AppendText("back_L2 : ObjType = " + back_L2.ObjType + Environment.NewLine);

            backArrayStr = back_L2.Obj.ToString();
            List <string> strList = (List <string>)JsonConvert.DeserializeObject(backArrayStr, typeof(List <string>));

            foreach (string key in strList)
            {
                Json_Parse_textBox.AppendText("=>" + key + Environment.NewLine);
            }
        }