繁体   English   中英

将 Json 反序列化为数组类型属性

[英]Deserializing Json to an Array type Propoerty

我是 Json 的新手。 我正在尝试从 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]"

我的目标是拥有一个 'Sources' 的对象,其中填充了 'SourceIds' 的值。

提前致谢,

我怀疑您的实际 Json 如下所示:

string jsonstring = " [
 {
      \"SourceIds\": 20181234
  },  
  {
      \"SourceIds\": 20181234
  },
 {
      \"SourceIds\": 20181234
  }
]"

你可以序列化你的json

var result = JsonConvert.DeserializeObject<IList<Class1>>(String)

序列化类

public class Class1
{
    public int SourceIds { get; set; }
}

小提琴

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM