调用newtonsoft.json反序列出错
调用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反序列出错的更多相关文章
- C# Newtonsoft.Json反序列化为dynamic对象之后的使用
通过Newtonsoft.Json将一个json类型的字符串反序列化为dynamic后直接使用报错 源代码: namespace ConsoleApplication1 { class Program ...
- 调用Newtonsoft.Json 报FileNotFoundException 错误
具体如下: Exception StackTrace at Newtonsoft.Json.Converters.BinaryConverter.CanConvert(Type objectType) ...
- DataTable转Json字符串(使用Newtonsoft.Json.dll)
DataTable转Json字符串(使用Newtonsoft.Json.dll) 在需要把DataTable转为Json字符串时,自己手动拼接太麻烦,而且容易出错,费时费力,使用Newtonsoft. ...
- Newtonsoft.Json序列化和反序列之javascriptConvert.SerializeObject,DeserializeObject,JsonWriter,JsonReader
这里下载:http://www.newtonsoft.com/products/json/安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2.在项目中添加引用.. jav ...
- (转)Newtonsoft.Json序列化和反序列
这里下载:http://www.newtonsoft.com/products/json/安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2.在项目中添加引用.. 序列化 ...
- Newtonsoft.Json序列化和反序列
这里下载:http://www.newtonsoft.com/products/json/安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2.在项目中添加引用.. 序列化 ...
- Newtonsoft.Json反序列化(Deserialize)出错:Bad JSON escape sequence
使用Newtonsoft.Json反序列化收到的字串为JObject或其它支持的数据模型,有时错误,提示如下: Bad JSON escape sequence: \c. Path , positio ...
- [Cannot deserialize JSON array into type] NewtonSoft.Json解析数据出错原因
今天用NewtonSoft.JSon解析一个天气数据,数据格式如: {"status":1,"detail":"\u6570\u636e\u83b7\ ...
- Newtonsoft.json 二次引用出错解决办法
一.一般在C# 项目中二次引用会出现如下错误: 解决办法:用编辑器打开项目下的文件(*.csproj),可以找到在这个文件中,Newtonsoft.Json的引用,删掉引用,然后在项目中重新引用就可以 ...
随机推荐
- JavaScript 数据类型判断
JavaScript 的数据类型分为两类:原始类型(基本类型)和对象类型(引用类型).原始类型包括数字.字符串和布尔值,另外有两个特殊的原始值:null 和 undefined,除此之外的都是对象.对 ...
- ae开发基础功能
放大.缩小.pan.框选要素(新建命令,建立命令HOOK,赋给当前地图控件): ICommand cmd = new ControlsSelectFeaturesTool(); cmd.OnCreat ...
- javascript 中 !~ 什么意思
快过年放假了,也终于闲下来了.每天游览于各种技术文章中,这种状态好极了.下午看篇关于js的文章,其中有如下这么一段引起了我的注意. (function () { var names = []; ret ...
- ECMAScript对文件夹图片幻灯片播放
代码如下: var curContext = null; var curWeb = null; var picListTitle = "PictureLib"; var folde ...
- pgRouting 2.0 for windows 来了
Postgres 9.2, PostGIS 2.0 and pgRouting 2.0 支持32.64 下载地址: http://winnie.postgis.net/download/window ...
- ios7 tableview被navigationbar挡住
用ego下拉刷新的时候,每次在ios7时,tableview都会上移...导致被navagationbar挡住.ios6是正常的,于是在init的时候添加如下代码... NSComparisonRes ...
- NSFileManeger
#define PATH @"/Users/wenhua/testdir" // 删除, 复制 剪切 这些行为都是管理文件的行为 //创建文件 void createFile(v ...
- 深入.net(多态一)
代码优化技术: 当您在 编写一个类时,如果您发现你需要编写的“属性”和“方法”曾经在已有的类中实现,则,您可以将其共用的“属性”和“方法”剪切到一个新的“类”中,然后,让两个类共同继承这个“新类”.( ...
- vs2013编译boost1.55.0 32/64位
在使用vs2013编译boost-1.55.0之前,先要给boost做下修改: boost_1_55_0\boost\intrusive\detail\has_member_function_call ...
- 编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。
package com.hanqi.test; public class Car { //构造一个汽车的属性 private String name; //创建getter和setter方法 publ ...