gpt4 book ai didi

c# - MVC4 Web API 返回带有特殊字符的 json propertykey 字符串

转载 作者:行者123 更新时间:2023-12-02 05:00:39 26 4
gpt4 key购买 nike

C# 不允许属性名称带有空格等特殊字符。需要有一种方法来定义像这样的 json 对象。有什么想法吗?

{
".Class1 #Id1" : "Value1"
".Class1 #Id2" : "Value2"
}

最佳答案

尝试使用 JsonProperty 属性:

        public class MyClass
{
[JsonProperty(".Class1 #Id1")]
public string id1 { get; set; }
[JsonProperty(".Class1 #Id2")]
public string id2 { get; set; }
}

关于c# - MVC4 Web API 返回带有特殊字符的 json propertykey 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17139078/

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