[英]Deserializing Json to an Array type Propoerty
I am new to Json.我是 Json 的新手。 I am trying to populate my object 'Sources' from json string with:
我正在尝试从 json 字符串填充我的对象“源”:
public class Sources
{
public long[] SourceIds;
}
string jsonstring = " [\r\n {\r\n \"SourceIds\": 20181234\r\n }, \r\n
{\r\n \"SourceIds\": 20181234\r\n },\r\n {\r\n \"SourceIds\":
20181234\r\n }\r\n]"
My aim is to have an object of 'Sources' with the values of 'SourceIds' populated.我的目标是拥有一个 'Sources' 的对象,其中填充了 'SourceIds' 的值。
Thanks in advance,提前致谢,
I suspect that your actual Json is like below:我怀疑您的实际 Json 如下所示:
string jsonstring = " [
{
\"SourceIds\": 20181234
},
{
\"SourceIds\": 20181234
},
{
\"SourceIds\": 20181234
}
]"
You can serialize your json with你可以序列化你的json
var result = JsonConvert.DeserializeObject<IList<Class1>>(String)
Serialization Classes序列化类
public class Class1
{
public int SourceIds { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.