首页 > 编程知识 正文

jobject获取值,jobject.parse

时间:2023-05-06 12:42:47 阅读:237902 作者:1923

一、JObject 和JArray的添加、修改、移除

1.先添加一个json字符串,把json字符串加载到JObject中,然后转换成JObject.根据索引修改对象的属性值,移除属性,添加属性

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Web;using GongHuiNewtonsoft.Json.Linq;namespace JSONDemo{ class Program { static void Main(string[] args) { string json = @"{ 'post':{ 'Title':'修改JArray和JObject', 'Link':'http://write.blog.csdn.net', 'Description':'这是一个修改JArray和JObject的演示案例', 'Item':[] } }"; JObject o = JObject.Parse(json); JObject post = (JObject)o["post"]; post["Title"] = ((string)post["Title"]).ToUpper(); post["Link"] = ((string)post["Link"]).ToUpper(); post.Property("Description").Remove(); post.Property("Link").AddAfterSelf(new JProperty("New", "新添加的属性")); JArray a = (JArray)post["Item"]; a.Add("修改JArray"); a.Add("修改JObject"); Console.WriteLine(o.ToString()); } }}


2.运行的结果

 

JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。