调用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. 百度编辑器 UEditor 报错汇总

    1,编辑文本时使用js将需要编辑内容setContent到编辑器里,总是报(IE8及IE11):'this.body' 为空或不是对象,详细如下,其实报这样的错除多半是加载先后或加载不完全导致的: 消 ...

  2. [javascript svg fill stroke stroke-width rx ry ellipse 属性讲解] svg fill stroke stroke-width ellipse 绘制椭圆属性讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  3. Linux下运行windows程序

    现在Winxp停止了支持,那我们的windows程序是否可以再linux上执行呢,如下是一些参考的信息 在您的 Linux/Mac 操作系统上运行 Windows 软件 http://www.wine ...

  4. 关于Android Force Close 出现的原因 以及解决方法

    一.原因: forceclose,意为强行关闭,当前应用程序发生了冲突. NullPointExection(空指针),IndexOutOfBoundsException(下标越界),就连Androi ...

  5. 通过settings.db自定义Android系统默认设置

    Android的系统设置数据存放在/data/data/com.android.providers.settings/databases/settings.db 中 数据库结构如下: 数据库中的默认数 ...

  6. Android项目编译和使用C语言动态库(so库)

    编译SO库 1.新建工程,建立jni目录用于放置c语言相关文件 2.编写Android.mk文件 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) ...

  7. iOS 获取设备版本型号

    #import "sys/utsname.h" /** *  设备版本 * *  @return e.g. iPhone 5S */+ (NSString*)deviceVersi ...

  8. iOS中UINavigationController控制器使用详解

    一.概述 UINavigationController用来管理视图控制器,在多视图控制器中常用.它以栈的形式管理视图控制器,管理视图控制器个数理论上不受限制(实际受内存限制),push和pop方法来弹 ...

  9. 安装php扩展

    下面我以soap安装为例子 cd /home/zhangy/php-5.2.6/ext/soap /usr/local/php/bin/phpize#确定php-config文件在不在,调用php-c ...

  10. js 静态私有变量

    特权方法:有权访问私有变量和私有函数的公有方法.在私有作用域中定义私有变量或函数,可以创建特权方法,如下: 示例1 (function(){ //私有变量和私有函数 var privateVariab ...