简体   繁体   English

Json.JsonSerializationException:无法反序列化当前 JSON 对象

[英]Json.JsonSerializationException : Cannot deserialize the current JSON object

My problem is that I'm getting this error when I try to deserialize my API json response.我的问题是当我尝试反序列化我的 API json 响应时出现此错误。

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Collections.Generic.List`1[Entities.JsonDataType]' because the type requires a JSON array (eg [1,2,3]) to deserialize correctly. Newtonsoft.Json.JsonSerializationException: '无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1[Entities.JsonDataType]' 因为该类型需要 JSON 数组(例如 [1,2,3]) 正确反序列化。

My json data return something like this我的 json 数据返回这样的东西

{
  "success": true,
  "result": [
    {
      "name": "USD Amerikan Doları",
      "buying": "6.6920",
      "selling": "6.6995"
    },
    {
      "name": "EUR Euro",
      "buying": "7.7322",
      "selling": "7.7393"
    },
    {
      "name": "GBP İngiliz Sterlini",
      "buying": "8.5933",
      "selling": "8.6041"
    },
    "..."
  ]
}

My class properties:我的班级属性:

public class JsonDataType
    {

        //public string name { get; set; }

        //public string buying { get; set; }

        //public string selling { get; set; }

        public bool success { get; set; }
        public List<Result> result { get; set; }
    }

    public class Result
    {
        public string name { get; set; }
        public string buying { get; set; }
        public string selling { get; set; }
    } 

And I'm getting the error when I deserialize:反序列化时出现错误:

List<JsonDataType> X = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JsonDataType>>(response.Content);

Also I tried these codes but none of them working我也试过这些代码,但没有一个工作

    JsonDataType X = JsonConvert.DeserializeObject(response.Content);

IEnumerable<Result> X = (JsonDataType)JsonConvert.DeserializeObject<IEnumerable<Result>>(response.Content, typeof(JsonDataType));

List<Result> X = JsonConvert.DeserializeObject<JsonDataType>(response.Content, typeof(Result));

If someone could help me i will be so peaceful.如果有人能帮助我,我会如此平静。 Thanks for your time in advance (✿◠‿◠)提前感谢您的时间(✿◠‿◠)

这是我的答案

JsonDataType X = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonDataType>(response.Content);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JsonSerializationException:无法反序列化当前的 JSON 对象 - JsonSerializationException: Cannot deserialize the current JSON object Newtonsoft.Json.JsonSerializationException:无法反序列化当前的JSON对象 - Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object Newtonsoft.Json.JsonSerializationException:&#39;无法反序列化当前JSON对象 - Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object C# JsonSerializationException 无法反序列化当前 JSON 对象 - C# JsonSerializationException Cannot deserialize the current JSON object Newtonsoft.Json.JsonSerializationException: '无法反序列化当前的 JSON object (例如 {"name":"value"}) - Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) Newtonsoft.Json.JsonSerializationException: &#39;无法反序列化当前的 JSON 数组 - Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array JsonSerializationException:无法将当前 JSON object(例如 {"name":"value"})反序列化为类型 'System.Collections。 - JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List 无法反序列化当前JSON对象 - Cannot deserialize the current JSON object 无法反序列化当前的JSON对象 - Cannot deserialize the current JSON object 无法反序列化当前的 JSON 对象 - Cannot deserialize the current JSON object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM