调用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的引用,删掉引用,然后在项目中重新引用就可以 ...
随机推荐
- Android高级模糊技术[转]
今天我们来更深入了解一下Android开发上的模糊技术.我读过几篇有关的文章,也在StackOverFlow上看过一些相关教程的帖子,所以我想在这里总结一下学到的东西. 为什么学习这个模糊技术? 现在 ...
- android加固系列—5.加固前先学会破解,hook(钩子)jni层系统api
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5138585.html] crackme项目jni的关键代码(项目地址见文章底部),获取当前程序 ...
- iOS指南针
前言: 这个小项目使用到了CoreLocation框架里面的设备朝向功能,对CoreLocation感兴趣的可以翻一下之前的文章 在另一个博客站有朋友发现一个尴尬的问题(图片的东西2个方向是不对的), ...
- 【代码笔记】iOS-缓存路径操作类
一,代码. AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplica ...
- 【代码笔记】iOS-日历
一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CalendarView.h ...
- 【代码笔记】iOS-点击顶点处,弹出另一个小的界面
一,效果图. 二,文件目录. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...
- 多线程(pthread、NSThread、GCD)
pthread C语言编写 跨平台可移植 线程生命周期需要我们来管理 使用困难 NSThread 面向对象的 可直接操作线程对象 线程生命周期需要我们来管理 使用简单 资源互斥(@synchroniz ...
- node.js使用汇总贴
金天:学习一个新东西,就要持有拥抱的心态,如果固守在自己先前的概念体系,就会有举步维艰的感觉..NET程序员初用node.js最需要适应的就是异步开发,以及弱类型语言难以避免的拼写错误与弱小的语法提示 ...
- 避坑宝典:如何选择HTML5游戏引擎
原生手游市场已是红海,腾讯.网易等寡头独霸天下,H5游戏市场成为下一个风口.据笔者所知,很多H5游戏开发团队由于选择引擎不慎导致项目甚至团队夭折. 如何选择适合团队和项目的引擎,笔者通过学习和项目实践 ...
- 海量IT资料 + 各种平台下的Oracle安装文件 + 公开课录像 + 各种视频教程资料
觉得老师的公开课讲的都挺好的,这里把我录的一些公开课视频分享给大家,都用的是<屏幕录像专家>来录制的,是lxe格式的,大家用这个软件来播放就可以了,后边的公开课录像文件也会慢慢添加进去的, ...