1.子类序列化 依赖父类属性

    [DataContract]
public class pcc
{
[DataMember]
public string Name { get; set; }
} public class ccc : pcc
{
public string cName { get; set; }
}

序列化 ccc 的时候, cName 不会被序列化!

由于ccc 的父类pcc 定义了 DataContract ,所以要求子类的所有属性要定义 DataMember 才能进行序列化。否则按 IgnoreDataMember 处理。

Json.Net,你 太自大了,谁给你的权力?!

修改源码

类:JsonTypeReflector.GetObjectMemberSerialization   想办法让它返回  MemberSerialization.OptOut

        public static MemberSerialization GetObjectMemberSerialization(Type objectType, bool ignoreSerializableAttribute)
{
JsonObjectAttribute objectAttribute = GetCachedAttribute<JsonObjectAttribute>(objectType);
if (objectAttribute != null)
return objectAttribute.MemberSerialization; #if !NET20
DataContractAttribute dataContractAttribute = GetDataContractAttribute(objectType);
if (dataContractAttribute != null)
return MemberSerialization.OptIn;
#endif #if !(NETFX_CORE || PORTABLE40 || PORTABLE)
if (!ignoreSerializableAttribute)
{
SerializableAttribute serializableAttribute = GetCachedAttribute<SerializableAttribute>(objectType);
if (serializableAttribute != null)
return MemberSerialization.Fields;
}
#endif // the default
return MemberSerialization.OptOut;
}
        public static DataContractAttribute GetDataContractAttribute(Type type)
{
// DataContractAttribute does not have inheritance
Type currentType = type; while (currentType != null)
{
DataContractAttribute result = CachedAttributeGetter<DataContractAttribute>.GetAttribute(currentType);
if (result != null)
return result; currentType = currentType.BaseType();
} return null;
}

原方法为:

        public static DataContractAttribute GetDataContractAttribute(Type type)
{
// DataContractAttribute does not have inheritance
Type currentType = type; while (currentType != null)
{
DataContractAttribute result = CachedAttributeGetter<DataContractAttribute>.GetAttribute(currentType);
if (result != null)
return result; currentType = currentType.BaseType();
} return null;
}

修改为:

        public static DataContractAttribute GetDataContractAttribute(Type type)
{
       //不判断基类的 DataContract 属性 by udi @2015年4月14日
return CachedAttributeGetter<DataContractAttribute>.GetAttribute(type);
}

即不判断基类的 DataContract 属性。

8.0.3 未解决。

2. 无法反序列化 英文日期

如:Apr 14, 2015 6:05:28 PM

找到: IsoDateTimeConverter.ReadJson

最后的代码:

            if (!string.IsNullOrEmpty(_dateTimeFormat))
return DateTime.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
else
return DateTime.Parse(dateText, Culture, _dateTimeStyles);

修改为:

            //在反序列化的时候,就不要使用 _dateTimeFormat 了,因为反序列的途径很多,而 _dateTimeFormat 指定的输出格式
var retDate = DateTime.MinValue;
if (DateTime.TryParse(dateText, out retDate))
{
return retDate;
} if (!string.IsNullOrEmpty(_dateTimeFormat))
return DateTime.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
else
return DateTime.Parse(dateText, Culture, _dateTimeStyles);

8.0.3 未解决

3. 还有未实现的属性

Json.Net 中 JObject , 继承自 IDictionary<string, JToken>,实现了 Keys , 但是没有实现 Values , 这个坑被我踩到了。艹,这玩意太他妈衰了!!!

        ICollection<JToken> IDictionary<string, JToken>.Values
{
get
{
// todo: need to wrap _properties.Values with a collection to get the JProperty value
throw new NotImplementedException();
}
}

修改为:

        ICollection<JToken> IDictionary<string, JToken>.Values
{
get
{
return _properties.Values.Values().ToList();
// todo: need to wrap _properties.Values with a collection to get the JProperty value
//throw new NotImplementedException();
}
}

这个问题到 8.0.3 一直没有解决

4. 版本 8.0.3 中 Newtonsoft.Json.Net40.sln 是使用 C#6.0编写的

调试 8.3 的时候发现的。 导致的问题是:Vs2013 编译不了 .net40.sln

vs2013 编译Json.Net 的问题

发现的 Vs2012,Vs2013编译问题

一个Solution,两个Web Mvc 项目(A,B),编译其中A,B无法运行(Json.net程序集变为了老的程序集),编译B,A无法运行(Json.net 程序集变为老的程序集)。

编译DbEnt,Mvc项目的bin里,也会自动Copy一些Dll,包含老的Json.Net 。

Json.Net 程序集并不是从指定目录Copy的。而是一个老版本, 4.5.11.* 。它是从 D:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend 这里Copy 的。

把D:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend 里的 json.net 删除,就好了。

关于修改Json.Net后,不能引用原来的Json.Net的问题

1.首先,修改Json.Net的在项目属性,程序集名称改为: MyJson , 也可以直接修改Dll的名字

2.添加MyJson的引用,在引用的Dll属性上,修改 别名 为: MyJson,默认是 global

3.在需要使用 MyJson 的地方,在文件最前面,添加 extern alias MyJson;

4.使用 MyJson:: 前缀,来指定 MyJson 程序集里的类。

5.如果使用新的 Json.Net 程序集类,则直接使用,无影响。

之前的文章:

http://www.cnblogs.com/newsea/archive/2010/02/25/1673468.html

Json.Net4.5 序列化问题的更多相关文章

  1. Python下Json和Msgpack序列化比较

     最近用Python时,遇到了序列化对象的问题,传统的json和新型序列化工具包msgpack都有涉及,于是做一个简单的总结: 通俗的讲:序列化:将对象信息转化为可以存储或传输的形式:反序列化:把这个 ...

  2. php json与xml序列化/反序列化

    在web开发中对象的序列化与反序列化经常使用,比较主流的有json格式与xml格式的序列化与反序列化,今天想写个jsop的小demo,结果发现不会使用php序列化,查了一下资料,做个笔记 简单数组js ...

  3. js实现对json数据的序列化(兼容ie6以上浏览器)

    /** * 增加对JSON数据的序列化方法, * 主要用于IE6.7不支持JSON对象的浏览器 */ var xue = xue || {};xue.json = xue.json || {}; xu ...

  4. 使用Json.NET来序列化所需的数据

    我们在做开发的时候,很多时候需要和Json数据格式打交道,如Web开发里面,很多时候,数据通过Json进行传递到页面上,然后在进行处理的.而使用Json的时候,我们很多时候会涉及到几个序列化对象的使用 ...

  5. Python之路-python(装饰器、生成器、迭代器、Json & pickle 数据序列化、软件目录结构规范)

    装饰器: 首先来认识一下python函数, 定义:本质是函数(功能是装饰其它函数),为其它函数添加附件功能        原则:        1.不能修改被装饰的函数的源代码.        2.不 ...

  6. 【ASP.NET Web API教程】6.2 ASP.NET Web API中的JSON和XML序列化

    谨以此文感谢关注此系列文章的园友!前段时间本以为此系列文章已没多少人关注,而不打算继续下去了.因为文章贴出来之后,看的人似乎不多,也很少有人对这些文章发表评论,而且几乎无人给予“推荐”.但前几天有人询 ...

  7. Java下利用Jackson进行JSON解析和序列化

    Java下利用Jackson进行JSON解析和序列化   Java下常见的Json类库有Gson.JSON-lib和Jackson等,Jackson相对来说比较高效,在项目中主要使用Jackson进行 ...

  8. Python-Day4 Python基础进阶之生成器/迭代器/装饰器/Json & pickle 数据序列化

    一.生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问前面几个元素,那后面 ...

  9. .net MVC 使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值

    在.net mvc的controller中,方法返回JsonResult,一般我们这么写: [HttpPost] public JsonResult QueryFeature(string url, ...

随机推荐

  1. IIS中使用LocalDB遇到错误:error 50,Local Database Runtime error occurred.的解决办法

    参见: [1] http://www.cnblogs.com/yjmyzz/archive/2009/10/26/1590033.html [2] http://blogs.msdn.com/b/sq ...

  2. unity3d 射弹基础案例

    小白本来想学cocos2dx的,然而c++难学就算了,cocos2dx对新手来说简直坑爹,于是乎转战unity3d学习js,在写出第一个游戏后兴致高多了哎. 回顾一下编辑的过程:1.建立一个cube作 ...

  3. 2016 ICPC北京站现场赛总结(再度流水账)

    其他的都先不说,北大的未名湖真的美! 虽然感觉北大其他地方都有些破旧之感,但是未名湖附近真的值得称赞. 在去北京之前就听说北京温度很低,不过是干冷,果不其然.北京不冷,就是嘴唇太干了,不喝水真的受不了 ...

  4. 【MVC】 非常简单的页面导出 WORD, EXCEL方法

    [MVC] 页面导出 WORD, EXCEL 前端 js function output() { var para = new Object(); para.html = getHtml(" ...

  5. Selenium2+python自动化8-SeleniumBuilder辅助定位元素

    前言 福利来了,对于用火狐浏览器的小伙伴们,你还在为定位元素而烦恼嘛? 上古神器Selenium Builder来啦,哪里不会点哪里,妈妈再也不用担心我的定位元素问题啦!(但是也不是万能,基本上都能覆 ...

  6. Java 基础知识总结 (二、基本数据类型)

    二.基本数据类型 java基本数据类型只能先声明后使用 boolean  true/false char 16-bit unicode character byte 8-bit integer sho ...

  7. 第二次作业#include <stdio.h> int main() { int a,b,c,d,e; printf("请输入一个不多于五位的整数:\n"); scanf("%d",&a); if(a>=100000||a<=0) { printf("输入格式错误! \n"); } else { if(

    1 判断成绩等级 给定一百分制成绩,要求输出成绩的等级.90以上为A,80-89为B,70-79为C,60-69为D,60分以下为E,输入大于100或小于0时输出"输入数据错误". ...

  8. [刘阳Java]_Java环境搭建_第2讲

    1.为什么搭建Java的环境 Java的程序语言不能独立在操作系统上运行 Java程序需要一个JVM(Java虚拟机)才能将程序员写好的Java程序运行在操作系统 Java程序的跨平台(Mac, Li ...

  9. 在windows环境下基于sublime text3的node.js开发环境搭建

    首先安装sublime text3,百度一堆,自己找吧.理论上sublime text2应该也可以.我只能说一句:这个软件实在是太强悍了. 跨平台,丰富的插件体系,加上插件基本上就是一个强悍的ide了 ...

  10. canvas 画六边形

    <section class="m1-c"> <div class="m1-t clearfix"> <ul> <li ...