2017-06-15 125 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; } 

    ... 
}