簡體   English   中英

如何使用JSON字符串符號傳遞作為另一個對象的成員的對象?

[英]How to pass an object that is a member of another object using JSON string notation?

好吧,我有這節課:

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"}]}

任何幫助表示贊賞。

C#類:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM