parliament
parliament

Reputation: 22914

Serialize to JSON with parenthesis in property name

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 ( ?

Upvotes: 1

Views: 647

Answers (1)

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

You can customize JSON property names with the JsonProperty attribute:

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

Upvotes: 4

Related Questions