C#生成JSON使用Newtonsoft.Json 最新方法
来源:互联网 发布:前端seo 编辑:程序博客网 时间:2024/06/05 19:16
1、JObject:基本的json对象
/// <summary> /// Gets the j object. /// </summary> /// <returns></returns> public JObject GetJObject() { var obj = new JObject {{"Name", "Mark" } }; return obj; }
2、JObject:嵌套子对象(JObject嵌JObject)
/// <summary> /// Gets the j object. /// </summary> /// <returns></returns> public JObject GetJObject() { var obj = new JObject {{"Name", "Mark"}, {"Age", 8 }}; var info = new JObject {{"Phone", "132****7777"}, {"Gender", "男"}}; obj.Add("Info", info); return obj; }
3、JArray:基本json对象中的数组
/// <summary> /// Gets the j array. /// </summary> /// <returns></returns> public JArray GetJArray() { var jarray = new JArray(); var mark = new JObject { { "Name", "Mark" }, { "Age", 8 } }; var jack = new JObject { { "Name", "Jack" }, { "Age", 9 } }; jarray.Add(mark); jarray.Add(jack); return jarray; }
4、JArray: 多个json对象数组
/// <summary> /// Gets the j array. /// </summary> /// <returns></returns> public JObject GetJArray() { var obj = new JObject(); var student = new JArray { new JObject {{ "Name", "Mark" }, { "Age", 8 } }, new JObject {{ "Name", "Jack" }, { "Age", 9 } } }; var results = new JArray { new JObject {{ "Subject", "语文"}, { "Score", 100}}, new JObject {{ "Subject", "数学" }, { "Score", 88}} }; obj.Add("Student", student); obj.Add("Results", results); return obj; }
5、JArray:json数组嵌套数组(一个学生对应多个课程分数)
/// <summary> /// Gets the results. /// </summary> /// <returns></returns> public JObject GetResults() { var mark = new JObject { { "Name", "Mark" }, { "Age", "8" } }; var results = new JArray { new JObject {{ "Subject", "语文"}, { "Score", 100}}, new JObject {{ "Subject", "数学" }, { "Score", 88}} }; mark.Add("Results", results); return mark; }
可以参考这两篇文章
http://blog.csdn.net/zxq1138634642/article/details/9044197http://www.cnblogs.com/mcgrady/archive/2013/06/08/3127781.html
阅读全文
0 0
- C#生成JSON使用Newtonsoft.Json 最新方法
- Newtonsoft.Json 方法使用
- c#操作json数据使用newtonsoft.json
- c#操作json使用newtonsoft.json
- C# 使用Newtonsoft.Json解析嵌套json
- C# 解析JSON -- Newtonsoft.Json
- C# 解析json Newtonsoft.json
- C# Newtonsoft json
- C# Newtonsoft.Json 操作
- Newtonsoft.Json 使用 C#序列号json,反序列化对象
- c# 在.NET使用Newtonsoft.Json转换,读取,写入json
- Newtonsoft.Json 使用 C#序列号json,反序列化对象
- C# 使用Newtonsoft.Json.dll 格式化显示Json串
- c# 在.NET使用Newtonsoft.Json转换,读取,写入json
- C# Json序列化工具--Newtonsoft.Json简介和使用
- c# 在.NET使用Newtonsoft.Json转换,读取,写入json
- C#中Newtonsoft.Json(Json.NET)的使用
- Newtonsoft.Json.dll使用
- weixin登录
- 欢迎使用CSDN-markdown编辑器
- Hadoop
- Request processing failed; nested exception is org.apache.ibatis.builder.IncompleteElementException
- 问题:Error: ' ' is not a valid resource name character
- C#生成JSON使用Newtonsoft.Json 最新方法
- Wireshark Wget bot木马分析
- Windows下Git多账号配置,同一电脑多个ssh-key的管理
- 公盘资源如何映射到本地电脑
- sqlsever修改表名,数据库名
- FileProvider
- 不正常国家 (树链剖分 可持久化Trie 启发式合并)
- 网络连接设备
- elasticsearch批量删除数据