2017-06-15 127 views
0

在做ReceiveJson()時,有什麼辦法映射不匹配的屬性名稱嗎?例如,JSON中的'user_name'應映射到C#對象中的'UserName'。FLURL:映射屬性名稱

List<Person> people = await _settings.Url 
    .AppendPathSegment("people") 
    .GetAsync() 
    .ReceiveJson<List<Person>>(); 

回答

3

Flurl使用Json.NET序列化,因此使用該庫的序列化屬性在你的模型,特別是JsonProperty,將實現你在找什麼:

using Newtonsoft.Json; 

public class Person 
{ 
    [JsonProperty("user_name")] 
    public string UserName { get; set; } 

    ... 
}