Json.Net Resolving Property Names Properly

前端 未结 2 438
余生分开走
余生分开走 2021-01-25 02:53

I am getting some data that looks like below JSON from an API

{
    body_html: \"

Test

\", id: \"cu1bpkz\", link_id: \"d3_3kkgis\",
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 03:59

    Use the JsonPropertyAttribute like so:

    [JsonProperty("author_flair_text")]
    public string AuthorFlairText { get; set; }
    

    This ensures it'll take the right name, different from the property in code.

    Edit: You can also use this tool for larger json files, it generates classes for your data: http://json2csharp.com/

提交回复
热议问题