调用newtonsoft.json反序列出错:

Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[WebService.Yeesky.JsonString]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'S', line 1, position 5.

贴一片E文solution:

 JsonConvert.DeserializeObject - Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[System.String]'

Run into this issue while consuming a 3rd party JSON API using JSON.NET.

Complete exception message:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[System.String]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

The json string I was trying to deserialize had a field looking like this:

"extras": {},

In my C# class that field was declared as a List<string>.
By declaring the field as an IDictionary<string, string> instead the problem was solved. Lesson learned: If the json value is '[]' => declare the field as List<type>
If the json value is '{}' => declare the field IDictionary<type, type>

调用newtonsoft.json反序列出错的更多相关文章

  1. C# Newtonsoft.Json反序列化为dynamic对象之后的使用

    通过Newtonsoft.Json将一个json类型的字符串反序列化为dynamic后直接使用报错 源代码: namespace ConsoleApplication1 { class Program ...

  2. 调用Newtonsoft.Json 报FileNotFoundException 错误

    具体如下: Exception StackTrace at Newtonsoft.Json.Converters.BinaryConverter.CanConvert(Type objectType) ...

  3. DataTable转Json字符串(使用Newtonsoft.Json.dll)

    DataTable转Json字符串(使用Newtonsoft.Json.dll) 在需要把DataTable转为Json字符串时,自己手动拼接太麻烦,而且容易出错,费时费力,使用Newtonsoft. ...

  4. Newtonsoft.Json序列化和反序列之javascriptConvert.SerializeObject,DeserializeObject,JsonWriter,JsonReader

    这里下载:http://www.newtonsoft.com/products/json/安装:   1.解压下载文件,得到Newtonsoft.Json.dll   2.在项目中添加引用.. jav ...

  5. (转)Newtonsoft.Json序列化和反序列

    这里下载:http://www.newtonsoft.com/products/json/安装:   1.解压下载文件,得到Newtonsoft.Json.dll   2.在项目中添加引用.. 序列化 ...

  6. Newtonsoft.Json序列化和反序列

    这里下载:http://www.newtonsoft.com/products/json/安装:   1.解压下载文件,得到Newtonsoft.Json.dll   2.在项目中添加引用.. 序列化 ...

  7. Newtonsoft.Json反序列化(Deserialize)出错:Bad JSON escape sequence

    使用Newtonsoft.Json反序列化收到的字串为JObject或其它支持的数据模型,有时错误,提示如下: Bad JSON escape sequence: \c. Path , positio ...

  8. [Cannot deserialize JSON array into type] NewtonSoft.Json解析数据出错原因

    今天用NewtonSoft.JSon解析一个天气数据,数据格式如: {"status":1,"detail":"\u6570\u636e\u83b7\ ...

  9. Newtonsoft.json 二次引用出错解决办法

    一.一般在C# 项目中二次引用会出现如下错误: 解决办法:用编辑器打开项目下的文件(*.csproj),可以找到在这个文件中,Newtonsoft.Json的引用,删掉引用,然后在项目中重新引用就可以 ...

随机推荐

  1. Autodesk 最新开发技术研讨会-北京-上海-武汉-成都-西安-PPT下载

    经过半月的奔波,转遍祖国大好河山.结论,还是喜欢成都,安逸~,好希望能在成都生活,竹林里品茶,不亦乐乎~ 如果你没能参加我们的研讨会,下面的PPT供参考: 面向世界.面向未来 – Autodesk 云 ...

  2. 愚人节大狂欢 – ADN DevBlog谎话连篇友谊赛

    愚人节过去了,你被捉弄了没有? :) 借这个机会,ADN的哥们儿也发泄狂欢了一把,我们4月1号当天在ADN DevBlog上发了一堆谎话连篇的blog,没有一个说实话的,哈哈.这是我们team内部进行 ...

  3. Android的消息循环机制 Looper Handler类分析

    Android的消息循环机制 Looper Handler类分析 Looper类说明   Looper 类用来为一个线程跑一个消息循环. 线程在默认情况下是没有消息循环与之关联的,Thread类在ru ...

  4. 转 #ifndef/#define/#endif使用详解

    想必很多人都看过“头文件中的 #ifndef/#define/#endif 防止该头文件被重复引用”.但是是否能理解“被重复引用”是什么意思?是不能在不同的两个文件中使用include来包含这个头文件 ...

  5. android deep link(深度链接)与自定义协议!

    此自定义仅供参考! 首先打开androidManifest.xml 在MainActivity中添加如下内容: <activity android:name=".MainActivit ...

  6. 用Reveal分析第三方App的UI

    文章出自:听云博客 Reveal简介: 这是个神奇的工具,它能常透彻地分析个App的UI结构. 这个工具包括两部分,部分是在PC上运行的一个独立应用,即Reveal.app,另一部分代码在你要分析的某 ...

  7. Android 中BaseActivty

    Base接口 IBaseActivity package liu.basedemo.base; /** * 基类接口 * Created by 刘楠 on 2016/7/28 0028.23:05 * ...

  8. iOS开发之AFN的基本使用

    本篇将从四个方面对iOS开发中经常使用到的AFNetworking框架进行讲解: 一.什么是 AFN 二.为什么要使用 AFN 三.AFN 怎么用 三.AFN和ASI的区别 一.什么是 AFN AFN ...

  9. C++ virtual虚函数

    #include<iostream> using namespace std; class Base{ public: void m() { cout << "it' ...

  10. vim添加Vundle插件

    1.git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 2.vim /etc/vimrc se ...