1

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

parliament
  • 20,000
  • 37
  • 141
  • 232
  • possible duplicate of [How can I parse a JSON string that would cause illegal C# identifiers?](http://stackoverflow.com/questions/24536533/how-can-i-parse-a-json-string-that-would-cause-illegal-c-sharp-identifiers) – Brian Rogers Feb 11 '15 at 19:55

1 Answers1

4

You can customize JSON property names with the JsonProperty attribute:

public class Request
{
    [JsonProperty("receiverList.receiver(0).email")]
    public string Email { get; set; }
}
Andrew Whitaker
  • 121,982
  • 31
  • 284
  • 303