C#- JSON的操作

 

 

            string jsonPath = System.Windows.Forms.Application.StartupPath + "\\Data\\probeData.json";
            string jsonString = File.ReadAllText(jsonPath);

            JObject obj;
            if (jsonString.Trim() == "")
                obj = new JObject();
            else
                obj = JObject.Parse(jsonString);

            JObject jArray = new JObject();

            JObject newObj = new JObject(
                    new JProperty("name", "5L64-0.8x10-C18"),
                    new JProperty("custom", 1.1),
                    new JProperty("freq", 2.1)
                );

            JObject newObj2 = new JObject(
                    new JProperty("name", "5L64-0.8x10-C18"),
                    new JProperty("custom", 1.3),
                    new JProperty("freq", 2.2)
                );

            jArray.Add("aaa4", newObj);
            jArray.Add("aaa6", newObj2);


            obj.Add("probe", jArray);




            //--------------------删除--------------------
            //JObject tokeselect = obj.SelectToken("probe") as JObject;
            //JObject tokeselect2 = tokeselect.SelectToken("aaa4") as JObject;
            ////tokeselect.Remove("aaa4");
            //tokeselect2.Remove("name");
            //--------------------删除--------------------

            //--------------------修改--------------------
            obj["probe"]["aaa4"]["name"] = "ccc123";

            jsonString = Convert.ToString(obj);
            System.Diagnostics.Trace.WriteLine(jsonString);

 

C#- JSON的操作

上一篇:学习node js 之微信公众帐号接口开发 准备工作


下一篇:WPF中如何优雅的实现INotifyPropertyChanged接口