反序列化json数据 [英] Deserialize the json data
问题描述
i想要反序列化json数据。
我的课程正在逐渐消失。< br $> b $ b
public class ServiceAgreementKey
{
public string abc {获得跨度>; set ; }
}
public class ServiceAgreementAddtionKey
{
public string 123 { get ; set ; }
}
public class ServiceAgreementAddition
{
public ServiceAgreementAddtionKey serviceAgreementAddtionKey { get ; set ; }
public int price { get 跨度>; set ; }
}
public class ServiceKit
{
public string Number {获得跨度>; set ; }
}
public class ServiceOccasion
{
public string serviceOccasionDate { get ; set ; }
public 列表< servicekit> serviceKits { get ; set ; }
}
public class RootObject
{
public ServiceAgreementKey serviceAgreementKey { get ; set ; }
public 列表< serviceagreementaddition> serviceAgreementAdditions { get ; set ; }
public 列表< serviceoccasion> serviceOccasions { get ; set ; }
我尝试过:
RootObject dataObjects = response.Content.ReadAsAsync< rootobject>()。结果;
i am得到followimng错误:
{无法将当前JSON对象(例如{\name \:\value \})反序列化为类型'System.Collections.Generic.List`1,因为该类型需要一个JSON数组(例如[1,2,3])才能正确反序列化。\\\ n要修复此错误要么将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,使其成为普通的.NET类型(例如,不是像整数那样的基本类型,不是像数组或List< t>这样的集合类型),可以从中反序列化JSON对象.JsonObjectAttribute也可以添加到类型中以强制它从JSON对象反序列化}
可以对此进行任何帮助......
谢谢...
Hi, 这篇关于反序列化json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
请考虑将您读取的数据保存到字符串变量中,并在问题中包含您尝试反序列化的JSON。
Hogan
i want to deserialize json data.
my class is fllowing way.
public class ServiceAgreementKey
{
public string abc{ get; set; }
}
public class ServiceAgreementAddtionKey
{
public string 123{ get; set; }
}
public class ServiceAgreementAddition
{
public ServiceAgreementAddtionKey serviceAgreementAddtionKey { get; set; }
public int price{ get; set; }
}
public class ServiceKit
{
public string Number { get; set; }
}
public class ServiceOccasion
{
public string serviceOccasionDate { get; set; }
public List<servicekit> serviceKits { get; set; }
}
public class RootObject
{
public ServiceAgreementKey serviceAgreementKey { get; set; }
public List<serviceagreementaddition> serviceAgreementAdditions { get; set; }
public List<serviceoccasion> serviceOccasions { get; set; }
What I have tried:
RootObject dataObjects = response.Content.ReadAsAsync<rootobject>().Result;
i am getting followimng error:
{"Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1 because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo 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}
can any onr help on this...
thanks...I've had excellent luck with Newtonsoft for JSON[^]. Its a popular nuget package.
Please consider saving the data you read into a string variable and include the JSON you're trying to deserialize in the question.
Hogan