反序列化JSON到数组类型属性

问题描述 投票:-2回答:1

我是新来的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]"

我的目标是具有与“SourceIds”填充“的值源头”的一个目的。

提前致谢,

c#
1个回答
0
投票

我怀疑你的实际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; }
}

Fiddle

© www.soinside.com 2019 - 2024. All rights reserved.