如何使用JSON字符串表示法传递作为另一个对象成员的对象
本文关键字:一个对象 成员 对象 JSON 何使用 字符串 表示 | 更新日期: 2023-09-27 18:12:21
我有这个类:
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; }
}
我想发布以下jsonstring,但它看不到,我试图添加值到帐户对象内的TAccount
类
jsonstring:
{ "TransactionAmount": 98, "Account":[{"Id" : 4 , "LastOperation" : "credit"}]}
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"
}
}