[英]Setting property name to include @ in JSON using System.Text.Json
I need to send via REST (not including some other sensitive information):我需要通过 REST 发送(不包括其他一些敏感信息):
{"@Scope": "Local"}
In the class file I JsonProperty
for Json.Net serialization:在 class 文件中 I
JsonProperty
for Json.Net 序列化:
[JsonProperty("@Scope")]
public string Scope { get; set; }
When putting together the json message to be sent via WebRequest, I have将要通过 WebRequest 发送的 json 消息放在一起时,我有
{@Scope = "Local"}
But after running:但运行后:
string jsonString = System.Text.Json.JsonSerializer.Serialize(message);
The message being sent out is发出的消息是
{"Scope": "Local"}
For some reason I though System.Text.Json will pick up JsonProperty
attributes but apparently there should be some other way.出于某种原因,我虽然 System.Text.Json 会获取
JsonProperty
属性,但显然应该有其他方式。
Try using尝试使用
[JsonPropertyName("@Scope")]
Instead of代替
[JsonProperty("@Scope")]
JsonProperty
might be for Newtonsoft which the built in serialization library probably does not recognize. JsonProperty
可能适用于内置序列化库可能无法识别的 Newtonsoft。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.