如何使用JSON字符串表示法传递作为另一个对象的成员的对象?

时间:2015-09-12 06:51:01

标签: c# json

我有这堂课:

public class TAccount
{
    public Account account { set; get; }
    public double transactionAmount { set; get; }
}

这节课:

public class Account
{
    public int Id { set; get; }
    public string AccountName { set; get; }
    public double Balance { set; get; }
    public string LastOperation { set; get; }

}

我想发布以下字符串,但是我无法看到我正在尝试将值添加到TAccount

中的Account对象

字符串:

{ "TransactionAmount": 98, "Account":[{"Id" : 4 , "LastOperation" : "credit"}]}

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

C#Classes:

public class TAccount
{
    public Account account { get; set; }
    public double transactionAmount { get; set; }
}


public class Account
{
    public int Id { get; set; }
    public string AccountName { get; set; }
    public double Balance { get; set; }
    public string LastOperation { get; set; }

}

尝试使用此结构发送:

{
    "transactionAmount": 98,
    "account": {
        "Id": 4,
        "LastOperation": "credit"
    }
}