UserBankCard userBankCard = new UserBankCard() { BankCard = bankCard, UserID = userID, RealName = realName, IDCard = IdCard, Phone = cardPhone, IsDefault = isDefault }; string key = ConfigurationManager.AppSettings["JuHeBankCardKey"]; //string bankcard = "6216910310203614"; //银行卡类型及真伪查询,接口请求地址 string apiUrl = "http://v.juhe.cn/bankcardinfo/query"; string resultJson = BankPayHelper.JuHeHttpPost(apiUrl, key, bankCard); //string resultJson = " { \"reason\":\"查询成功 \",\"result\":{ \"bank\":\"中国民生银行\",\"cardtype\":\"借记卡\",\"nature\":\"借记卡普卡\",\"kefu\":\"95568\",\"bankcard\":\"621691031020361\",\"logo\":\"http://apiserver.qiniudn.com/minsheng.png\",\"info\":\"\"},\"error_code\":0} "; if (RegExp.IsNull(resultJson)) { return Json(JsonAjax.JsonResult("0", "返回请求Json为空,请检查日志")); } try { JuheBankCardResponse bankCardResponse = new JuheBankCardResponse(); List<JuHeBankCardResult> bankCardResult = new List<JuHeBankCardResult>(); bankCardResponse.result = bankCardResult; Dictionary<string, object> dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(resultJson); foreach (var item in dic) { if (item.Key == "reason") { bankCardResponse.reason = item.Value.ToString(); } if (item.Key == "result") { if (item.Value != null) { JuHeBankCardResult bankCardResultDic = new JuHeBankCardResult(); bankCardResultDic = JsonConvert.DeserializeObject<JuHeBankCardResult>(item.Value.ToString()); bankCardResult.Add(bankCardResultDic); userBankCard.BankName = bankCardResultDic.bank; userBankCard.CardType = bankCardResultDic.cardtype; userBankCard.CardNature = bankCardResultDic.nature; userBankCard.Kefu = bankCardResultDic.kefu; userBankCard.LogoUrl = bankCardResultDic.logo; userBankCard.BankInfo = bankCardResultDic.info; userBankCard.Status = (int)BankCardStatus.Normal;//是否删除 userBankCard.CreateDate = DateTime.Now; userBankCard.UpdateDate = null; } } if (item.Key == "error_code") { bankCardResponse.error_code = Convert.ToInt32(item.Value); if (Convert.ToInt32(item.Value) != 0) { LogHelper.Error("[ShopBankCard]银行支付银行卡类型及真伪查询失败,查询的银行卡号:" + bankCard + "。接口返回失败原因:" + bankCardResponse.reason + "。" + currentPageLog); return Json(JsonAjax.JsonResult("0", "银行卡类型及真伪查询失败," + bankCardResponse.reason)); } } } } catch (Exception ex) { LogHelper.RecordErro("银行卡类型及真伪查询报错" + currentPageLog, ex); return Json(JsonAjax.JsonResult("-1", "银行卡类型及真伪查询报错")); }
标签:userBankCard,C#,bankCardResponse,reason,item,json,序列化,bankCardResultDic,string From: https://www.cnblogs.com/jankie1122/p/11108646.html