qq_35600549
丶best
采纳率0%
2016-07-14 02:33 阅读 4.6k

c#将一个对象转换成json

c#将一个对象转换成json
class AllyRequestIO
{
/*//请求随机数
private String random { get; set; }
//请求参数
private String iparams { get; set; }*/

    public String token { get; set; }
    public int payType { get; set; }
    public Decimal amount { get; set; }
    public String use { get; set; }
    public String remark { get; set; }
    public String orgId { get; set; }
    public long merchantId { get; set; }
    public String pbucode { get; set; }
    public String accno { get; set; }
    public String accname { get; set; }
    public String bankcode { get; set; }
    public String ubankno { get; set; }
    public String cusno { get; set; }
    public int acctype { get; set; }
}

                AllyRequestIO aio = new AllyRequestIO();
        aio.token = "e993ffb0-54a7-4446-8b17-937f1454d214";
        aio.payType = 1;
        aio.amount = (Decimal)111.00;
        aio.use = "余额充值";
        aio.remark = "用户:超级管理员充值余额";
        aio.orgId="DDA607C7-C875-4B3A-AA29-4D435F2A4295";
        aio.merchantId = 1;
        aio.pbucode = "TEST";
        aio.accno = "6225842255849524451";
        aio.accname = "李四";
        aio.bankcode = "CCB";
        aio.ubankno = "衣冠庙支行";
        aio.cusno = "3625";
        aio.acctype = 2;


                    我要将aio转换成json,怎么做?
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

6条回答 默认 最新

  • u012439689 蛋蛋fighting哈湫 2016-07-14 02:44

    利用DataContractJsonSerializer类, 加这个引用System.Runtime.Serialization.Json; string jsonString = Jsonlper.JsonSerializer(aio);序列化之后就是json字符串了

    点赞 3 评论 复制链接分享
  • goldenbull9 goldenbull9 2016-07-16 06:58

    nuget安装Json.NET

    string json = JsonConvert.SerializeObject(aio);
    var aio2 = JsonConvert.DeserializeObject(json);

    点赞 2 评论 复制链接分享
  • wingtious wingtious 2016-07-14 03:02

    同求~~~~~~~~~

    点赞 1 评论 复制链接分享
  • harryqqai harryqqai 2016-07-16 06:16

    ystem.Runtime.Serialization.Json; string jsonString = Jsonlper.JsonSerializer(aio);

    点赞 1 评论 复制链接分享
  • goldenbull9 goldenbull9 2016-07-16 06:57

    nuget安装Json.NET

    string json = JsonConvert.SerializeObject(aio);
    var aio2 = JsonConvert.DeserializeObject<AllyRequestIO>(json); 
    
    点赞 1 评论 复制链接分享
  • shicl shicl 2016-07-14 05:34

    var serializer = new DataContractJsonSerializer(typeof(AllyRequestIO ));
    var stream = new MemoryStream();
    serializer.WriteObject(stream, config);

    点赞 评论 复制链接分享

相关推荐