在属性名称中带有括号的序列化为JSON

在属性名称中带有括号的序列化为JSON

本文介绍了在属性名称中带有括号的序列化为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paypal api进行一些付款工作.

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

如果我查看 SetExpressCheckout ,则某些字段为以下形式PAYMENTREQUEST_n_AMT.对我来说很好,因为我有一个这样的请求类:

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; }
}

那行得通.现在,我需要使用 PAY操作,其字段如下

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

receiverList.receiver(0).email

由于c#属性名称中不允许使用括号,因此我应该如何在请求类上编写相应的属性.我宁愿不使用Dictionary<string, string>.

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>.

我可以配置JSON.net来处理将_转换为(吗?

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

推荐答案

您可以使用JsonProperty属性来自定义JSON属性名称:

You can customize JSON property names with the JsonProperty attribute:

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

这篇关于在属性名称中带有括号的序列化为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 07:24