Serialize to JSON with parenthesis in property name

梦想的初衷 提交于 2020-04-07 06:15:10

问题


I'm using paypal api to do some payment stuff.

If I look at SetExpressCheckout some field are in the form PAYMENTREQUEST_n_AMT. That's fine for me because I has a request class like this:

public class SetExpressCheckoutRequest 
{
     public string PAYMENTREQUEST_0_AMT { get; set; }
}  

That works. Now I need to use the PAY operation which has fields like

receiverList.receiver(0).email 

Since parenthesis are not allowed in c# property names, how am I supposed to write a corresponding property on my request class. I would prefer not to use Dictionary<string, string>.

Can I configure JSON.net to handle an alternative like convert _ to ( ?


回答1:


You can customize JSON property names with the JsonProperty attribute:

public class Request
{
    [JsonProperty("receiverList.receiver(0).email")]
    public string Email { get; set; }
}


来源:https://stackoverflow.com/questions/28461265/serialize-to-json-with-parenthesis-in-property-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!