且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Newtonsoft json反序列化问题

更新时间:2023-02-17 20:03:48

你的问题非常清楚。



Your issue is pretty clear.

引用:

无法将当前的JSON对象(例如{name:value})反序列化为输入'System.Collections.Generic.List`1 [Mahendras.API.response]'

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





它甚至告诉你你需要做什么修复它。





And it even tells you what you need to do to fix it.

引用:

要修复此错误,请将JSON更改为一个JSON数组(例如[1,2,3])或更改反序列化类型以使其正常

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





您的班级表示可以有很多回复(列表或数组)但您提供的json示例将响应作为对象。这就是为什么你不能反序列化json对象列表,因为你的json不是列表的格式。



更改 public List&lt ;响应> res_data {get;组; } 公共响应res_data {get;组; } 并且你应该可以反序列化你的json字符串。



Your class is saying that there can be many responses (a list or an array) but your json example you've provided has the response as an object. This is why you are getting cannot deserialize json object to list because your json isn't in the format of a list.

Change public List<response> res_data { get; set; } to be public response res_data { get; set; } and you should be able to deserialize your json string.