Пример #1
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);
        }
Пример #2
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);
            }
        }