[英]Newtonsoft.Json.JsonSerializationException
i'm trying to convert the json to C# objects by the statement 我正在尝试通过以下语句将json转换为C#对象
var organizations = response.Content.ReadAsAsync<IEnumerable<Organization>>().Result;
i found so many questions like the same what i'm facing now but i didn't found the proper answer may i know the reason for this exception 我发现了很多问题,就像我现在面临的问题一样,但是我没有找到正确的答案,也许我知道发生此异常的原因
Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Collections.Generic.IEnumerable `1[ConsoleApplication2.Organization]' because the type requires a JSON array (eg [1,2,3]) to deserialize correctly.
无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型'System.Collections.Generic.IEnumerable'1 [ConsoleApplication2.Organization]',因为该类型需要JSON数组(例如[1,2, 3])正确反序列化。
To fix this error either change the JSON to a JSON array (eg [1,2,3]) or change the deserialized type so that it is a normal .NET type (eg not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object.
要解决此错误,可以将JSON更改为JSON数组(例如[1,2,3]),也可以更改反序列化类型,使其成为普通的.NET类型(例如,不像整数这样的原始类型,也不像这样的集合类型数组或列表),可以从JSON对象反序列化。 JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。
i'm trying to convert the json to C# objects by the statement i found so many questions like the same what i'm facing now but i didn't found the proper answer may i know the reason for this exception my Json is 我试图通过该语句将json转换为C#对象,发现很多问题都与我现在面临的问题相同,但是我没有找到正确的答案,也许我知道造成这种异常的原因,我的Json是
{
"code": 0,
"message": "success",
"organizations": [
{
"organization_id": "10234695",
"name": "Zillium Inc",
"contact_name": "John Smith",
"email": "johnsmith@zilliuminc.com",
"is_default_org": false,
"plan_type": 0,
"tax_group_enabled": true,
"plan_name": "TRIAL",
"plan_period": "",
"language_code": "en",
"fiscal_year_start_month": 0,
"account_created_date": "2012-02-18",
"account_created_date_formatted": "18 Feb 2012",
"time_zone": "Asia/Calcutta",
"is_org_active": true,
"currency_id": "460000000000097",
"currency_code": "USD",
"currency_symbol": "$",
"currency_format": "###,##0.00",
"price_precision": 2
},
{
"organization_id": "10407630",
"name": "Winston Longbridge",
"contact_name": "John Smith",
"email": "johnsmith@zilliuminc.com",
"is_default_org": false,
"plan_type": 0,
"tax_group_enabled": true,
"plan_name": "TRIAL",
"plan_period": "",
"language_code": "en",
"fiscal_year_start_month": 0,
"account_created_date": "2012-07-11",
"account_created_date_formatted": "11 Jul 2012",
"time_zone": "Asia/Calcutta",
"is_org_active": true,
"currency_id": "541000000000099",
"currency_code": "INR",
"currency_symbol": "Rs.",
"currency_format": "###,##0.00",
"price_precision": 2
}
]
}
You are trying to deserialize into an IEnumerable<Organization>>
which is a list an therefor the serializer expects a json string defining a list/array like [{a:b}, {a:n}]
您正在尝试反序列化为
IEnumerable<Organization>>
,这是一个列表,因此序列化程序期望json字符串定义一个列表/数组,例如[{a:b}, {a:n}]
Your json data seems to be a normal json object and not an array. 您的json数据似乎是普通的json对象,而不是数组。
This is causing the exception. 这导致了异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.