簡體   English   中英

RestSharp - 帶有“$”響應屬性名稱的 GET 請求

[英]RestSharp - GET request with “$” response attribute name

我需要從 REST API 獲得 GET 響應。 我使用 RestSharp。 問題是,響應屬性的一個名稱是“$”。 這是回應:

[
    {
        "CodeId": {
            "$": "00000000"
        },
        "Entity": {
            "LegalName": {
                "@xml:lang": "cs",
                "$": "xxxxx"
            }
        }
    }
]

我應該如何使用 RestSharp 來獲取 Entity.LegalName.$ 的值?

感謝@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);

測試休息響應模板:

  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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM