下面是代码片段是我的json对象,我想用我的模型绑定数据。和 我想只将transaction_details值提取到我的样本模型中作为列表。
{
"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 :(得分: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)
{
}