JSON使用ObjectCreationHandling 反序列化替换不重复的值
来源:互联网 发布:苹果接电话变声软件 编辑:程序博客网 时间:2024/05/20 09:27
1.首先创建一个实例对象City,并声明构造函数.
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace JSONDemo{ public class City { public string Country { get; set; } public IList<string> Name { get; set; } public City() { this.Name = new List<string> { "Auckland", "Wellington", "Hamilton" }; } }}
2.JSON反序列化数据
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using GongHuiNewtonsoft.Json;namespace JSONDemo{ class Program { static void Main(string[] args) { string json = @"{ 'Country':'New Zealand', 'Name':[ 'Auckland', 'Christchurch', 'Dunedin' ] }"; Console.WriteLine("---------------替换前----------------"); City city1 = JsonConvert.DeserializeObject<City>(json); foreach (string name in city1.Name) { Console.WriteLine(name); } Console.WriteLine("-------------替换后-------------------"); City city2 = JsonConvert.DeserializeObject<City>(json, new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }); foreach (string name in city2.Name) { Console.WriteLine(name); } } }}
3.运行的结果
JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751
0 0
- JSON使用ObjectCreationHandling 反序列化替换不重复的值
- JSON使用MissingMemberHandling 反序列化对象中不匹配成员的异常
- json的反序列化
- json 反序列化
- Json反序列化
- json反序列化
- json反序列化
- 反序列化Json
- Json工具类--使用json-lib实现json的序列化和反序列化
- JSON反序列化的方法
- Android Json数据的反序列化
- json数组的反序列化
- json多层数组的反序列化
- Newtonsoft.Json 使用 C#序列号json,反序列化对象
- mvc使用Newtonsoft.Json反序列化json数据
- Newtonsoft.Json 使用 C#序列号json,反序列化对象
- Json.NET使用入门(四)【复杂Json反序列化】
- 使用Newtonsoft.Json进行JSON反序列化操作
- c语言输入生日显示星座
- 2 Which of the following cannot be used as input to the SQL Tuning Advisor? (Choose all that apply.)
- SVN服务器迁移客户端配置更改说明【Windows & Mac】
- spring框架初步了解(第二篇)
- iOS系列UI篇——UIVisualEffectView
- JSON使用ObjectCreationHandling 反序列化替换不重复的值
- Xcode7使用MJ的NSObject+Value出现Too many arguments to function call,expected 0,have 3
- c语言输入菱形
- android中的Handler和Callback机制
- 第十二周项目4-利用遍历思想求解图问题(7)
- js中typeof的用法汇总
- 编程判断3人中谁的年龄最大,并打印最大者的年龄
- 第四周 项目四 建设双链表算法库
- LeetCode 222 Count Complete Tree Nodes