[英]RestSharp - GET request with “$” response attribute name
I need to get GET response from REST API.我需要从 REST API 获得 GET 响应。 I use RestSharp.
我使用 RestSharp。 The problem is, that one name of the response attribute is "$".
问题是,响应属性的一个名称是“$”。 This is the response:
这是回应:
[
{
"CodeId": {
"$": "00000000"
},
"Entity": {
"LegalName": {
"@xml:lang": "cs",
"$": "xxxxx"
}
}
}
]
How should I use the RestSharp to get the value of Entity.LegalName.$?我应该如何使用 RestSharp 来获取 Entity.LegalName.$ 的值?
I found the answer thanks by @fredrik.感谢@fredrik,我找到了答案。
var client = new RestClient(url);
var request = new RestRequest(urlRequest, DataFormat.Json);
var response = client.Get(request);
Console.WriteLine(JsonSerializer.Deserialize<List<TestRestResponseTemplate>>(response.Content)[0].Entity.LegalName.Value);
TestRestResponseTemplate:测试休息响应模板:
public class TestRestResponseTemplate
{
public Entity Entity { get; set; }
}
public class LegalName
{
[JsonPropertyName("@xml:lang")]
public string Language { get; set; }
[JsonPropertyName("$")]
public string Value { get; set; }
}
public class Entity
{
public LegalName LegalName { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.