gpt4 book ai didi

c# - 牛顿软件.JSON : JSON List and Array are handled differently

转载 作者:太空狗 更新时间:2023-10-30 01:31:44 24 4
gpt4 key购买 nike

<分区>

给定以下代码:

public class ColorList 
{
public List<string> Colors = new List<string>(new string[1] { "#eeeeee"});
}
public class ColorArray
{
public string[] Colors = new string[1] { "#eeeeee"};
}

public class Program
{
public static void Main()
{
string json = "{Colors:['#abc','#123']}";

// Deserialize Colors into List:
Console.WriteLine(JsonConvert.DeserializeObject<ColorList>(json).Colors.Count);
// returns 3
// Deserialize Colors into Array:
Console.WriteLine(JsonConvert.DeserializeObject<ColorArray>(json).Colors.Length);
// returns 2
}
}

为什么这两个反序列化有区别?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com