且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用"0"将JSON解析为C#对象.作为JSON字符串中的对象名称

更新时间:2023-09-05 21:28:04

我相信您可以使用json.NET的property属性系统来更正此问题,文档位于此处. http://james.newtonking.com/json/help /index.html?topic=html/SerializationAttributes.htm

I believe you can use json.NET's property attribute system to correct this, the docs are here. http://james.newtonking.com/json/help/index.html?topic=html/SerializationAttributes.htm

public class ToClass 
{
    public Data[];
    [JsonProperty(PropertyName = "0")]
    public zero Zero = new zero();
}

这将使反序列化器将名为0的json属性与名为Zero

This will make it so the deserializer equates the json property named 0 with the C# property named Zero