2017-03-04 24 views
1

以下はコードスニペットです。私のモデルとデータをバインドするjsonオブジェクトです。そして 私はリストとして私のサンプルモデルにtransaction_details値だけを抽出したいと思います。C#のjsonオブジェクトから値を抽出する方法

{ 
    "status": 1, 
    "msg": "3 out of 3 Transactions Fetched Successfully", 
    "transaction_details": { 
    "446094091884bf8534e6": { 
     "mihpayid": "00000000003", 
     "request_id": "", 
     "bank_ref_num": "1154234544", 
     "amt": "1.00", 
     "transaction_amount": "1.00", 
     "txnid": "446094091884bf8534e6", 
     "additional_charges": "0.00", 
     "productinfo": "Buy Bitcoin", 
     "firstname": "Pramod", 
     "bankcode": "ICIB", 
     "udf1": "", 
     "udf3": "", 
     "udf4": "", 
     "udf5": "", 
     "field9": "Successful Transaction", 
     "error_code": "E000", 
     "card_type": null, 
     "error_Message": "NO ERROR", 
     "net_amount_debit": 1, 
     "disc": "0.00", 
     "mode": "NB", 
     "PG_TYPE": "ICICI", 
     "card_no": "", 
     "udf2": "", 
     "addedon": "2017-02-24 12:14:03", 
     "status": "success", 
     "unmappedstatus": "captured", 
     "Merchant_UTR": "dfksdfld", 
     "Settled_At": "0000-00-00 00:00:00" 
    }, 
    "446094091884bf8534e7": { 
     "mihpayid": "00000000002", 
     "request_id": "", 
     "bank_ref_num": "1154392922", 
     "amt": "1.00", 
     "transaction_amount": "1.00", 
     "txnid": "446094091884bf8534e7", 
     "additional_charges": "0.00", 
     "productinfo": "Buy Bitcoin", 
     "firstname": "Pramod", 
     "bankcode": "ICIB", 
     "udf1": "", 
     "udf3": "", 
     "udf4": "", 
     "udf5": "", 
     "field9": "Successful Transaction", 
     "error_code": "E000", 
     "card_type": null, 
     "error_Message": "NO ERROR", 
     "net_amount_debit": 1, 
     "disc": "0.00", 
     "mode": "NB", 
     "PG_TYPE": "ICICI", 
     "card_no": "", 
     "udf2": "", 
     "addedon": "2017-02-24 16:38:00", 
     "status": "success", 
     "unmappedstatus": "captured", 
     "Merchant_UTR": "fasdfafasdfsd", 
     "Settled_At": "0000-00-00 00:00:00" 
    }, 
    "446094091884bf8534e8": { 
     "mihpayid": "00000000001", 
     "request_id": null, 
     "bank_ref_num": null, 
     "amt": "1.00", 
     "transaction_amount": "1.00", 
     "txnid": "446094091884bf8534e8", 
     "additional_charges": "0.00", 
     "productinfo": "Buy Bitcoin", 
     "firstname": "Pramod", 
     "bankcode": "ICIB", 
     "udf1": "", 
     "udf3": "", 
     "udf4": "", 
     "udf5": "", 
     "field9": "User interrupted by pressing back button", 
     "error_code": "E1206", 
     "card_type": null, 
     "error_Message": "Transaction interrupted by pressing back button", 
     "net_amount_debit": "0.00", 
     "disc": "0.00", 
     "mode": "NB", 
     "PG_TYPE": "ICICI", 
     "card_no": "", 
     "udf2": "", 
     "addedon": "2017-02-27 14:03:00", 
     "status": "failure", 
     "unmappedstatus": "userCancelled", 
     "Merchant_UTR": null, 
     "Settled_At": null 
    } 
    } 
} 

この私のサンプルモデル

public class sample 
{ 
    public string mihpayid { get; set; } 
    public string request_id { get; set; } 
    public string bank_ref_num { get; set; } 
    public string amt { get; set; } 
    public string transaction_amount { get; set; } 
    public string txnid { get; set; } 
    public string additional_charges { get; set; } 
    public string productinfo { get; set; } 
    public string firstname { get; set; } 
    public string bankcode { get; set; } 
    public string udf1 { get; set; } 
    public string udf3 { get; set; } 
    public string udf4 { get; set; } 
    public string udf5 { get; set; } 
    public string field9 { get; set; } 
    public string error_code { get; set; } 
    public string card_type { get; set; } 
    public string error_Message { get; set; } 
    public string net_amount_debit { get; set; } 
    public string disc { get; set; } 
    public string mode { get; set; } 
    public string PG_TYPE { get; set; } 
    public string card_no { get; set; } 
    public string udf2 { get; set; } 
    public string addedon { get; set; } 
    public string status { get; set; } 
    public string unmappedstatus { get; set; } 
    public string Merchant_UTR { get; set; } 
    public string Settled_At { get; set; } 
} 
+0

postメソッド私はJSONオブジェクトから実際の値を抽出したい –

+0

を使用してコントローラに送信する必要がjusrtます。 –

+0

コントローラまたはjqueryで抽出する場所コントローラで私の答えをchkしてください –

答えて

0
for c# 
    var jsonSerializer = new JavaScriptSerializer(); 
    var objsample = jsonSerializer.Deserialize<sample>(jsonInput) 

    // for mvc 

    $.ajax({ 
     url: '/submit', 
     data: JSON.stringify(yourdatastring), 
     type: 'POST', 
     contentType: 'application/json; charset=utf-8' 
    }); 

    **Controller** 

    [HttpPost] 
    public void Submit ([FormBody] Sample sample) 
    { 
    } 
関連する問題