【问题标题】:getting some values from JSON string in C#? [duplicate]从 C# 中的 JSON 字符串获取一些值? [复制]
【发布时间】:2016-03-06 17:26:08
【问题描述】:

字符串来源

{
"Amount": 16700000,
"CardNumber": "0095",
"MerchantReference": "7654325",
"PaymentReference": "FBN|WEB|WEBP|3-02-2016|170619",
"RetrievalReferenceNumber": "000000088836",
"LeadBankCbnCode": null,
"LeadBankName": null,
"SplitAccounts": [],
"TransactionDate": "2016-02-03T16:41:43.923",
"ResponseCode": "00",
"ResponseDescription": "Approved Successful"
}

如何使用 c# 获取 Transaction DateResponseDescriptionTransaction date 的值。 谢谢

【问题讨论】:

    标签: c# json


    【解决方案1】:

    看看这个库:https://www.nuget.org/packages/Newtonsoft.Json。 这是代码。首先,定义要在其中放置值的对象。例子:

    [Serializable]
    public class TransactionResponse
    {
        public DateTime TransactionDate { get; set; }
        public string ResponseCode { get; set; }
        public string ResponseDescription { get; set; }
    }
    

    然后,像这样使用你的类:

    using Newtonsoft.Json;
    

    ...

    string jsonContent = @"{
    ""Amount"": 16700000,
    ""CardNumber"": ""0095"",
    ""MerchantReference"": ""7654325"",
    ""PaymentReference"": ""FBN|WEB|WEBP|3-02-2016|170619"",
    ""RetrievalReferenceNumber"": ""000000088836"",
    ""LeadBankCbnCode"": null,
    ""LeadBankName"": null,
    ""SplitAccounts"": [],
    ""TransactionDate"": ""2016-02-03T16:41:43.923"",
    ""ResponseCode"": ""00"",
    ""ResponseDescription"": ""Approved Successful""
    }";
    
    var response = JsonConvert.DeserializeObject<TransactionResponse>(jsonContent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2020-10-31
      相关资源
      最近更新 更多