C# 给出json作为响应,但不确定如何解析它

C# 给出json作为响应,但不确定如何解析它,c#,json,.net-4.7,C#,Json,.net 4.7,我正在使用此代码尝试从支付网关解析回我的响应: var responseMessage = client.PostAsJsonAsync("transaction", transData).Result; var response = responseMessage.Content.ReadAsStringAsync().Result; MessageBox.Show(response); JavaScriptSerializer jsonSerializer = new Jav

我正在使用此代码尝试从支付网关解析回我的响应:

 var responseMessage = client.PostAsJsonAsync("transaction", transData).Result;
  var response = responseMessage.Content.ReadAsStringAsync().Result;
  MessageBox.Show(response);

  JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
  var objCustomer = jsonSerializer.Deserialize<ReturnValues.RootObject>(response);
我得到的答复如下:

“数据”收集:““id”id\”::“id”id\“:::“BP2Pa41EPTuTupu3Q11,”,”用户身份id\“,“用户id id”用户id\“::“用户id”身份:“:“BMBMBMBMS9EDTTTTTTT钱钱钱钱\\”:::“成功\”,,“成功\”,,,“成功\”,,,,“““““,,,,““““,,,“用户身份身份身份id\”,,,,,,,“用户id”身份id\”:::::::::::::::::::::“成功\“成功\”,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“成功捕获\“:1000,\”已结算金额“:0、”退款金额“:0、”付款调整“:0、”小费金额“:0、”结算批次id“:“,”处理者id“:”bmibnfperttqdc2kigmg“,”处理者类型“:”tsys\u sierra“,”处理者名称“:”键控 信用 卡“,”支付方式“:”卡“,”支付类型“:”卡“,”功能“:[”avs“,”卡验证“,”二级“,”假应答“],”国税金额“:0,“”税款金额“:0,“”从邮政编码发货“:”,”商品代码摘要“:”,”商户增值税注册号“,”客户增值税注册号“,”客户增值税注册号“:”0,”免税\“:假、\”运费\“:0、\”附加费\“:0、\”折扣\“:0、\”货币\“:\”美元\“、\”说明\“:\”此 是一个 在测试中,“订单-U-U-id”的测试部分,“订单-U-U-U-id”的测试部分,“订单-U-U-id”的测试部分,“订单-U-U-id id”的测试部分除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了之外之外之外之外之外之外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外以外的其他外,除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了卡片\“:{\“id\”:\”BP2PA41ERTUPU3Q1EO0“,”卡片类型“:”visa“,”first\u six“:”401288“,”last\u four“:”1881“,”蒙面卡“:”401288****1881“,”到期日期“:”12/21“,”响应“:”已批准“,”响应代码“:”100,“认证代码“:”TAS000“,”响应代码“:”文本处理器“:”00 塔斯000 \“处理器”类型:“,“处理器”身份识别号:“,,,“处理器”类型:“,“处理器”类型:“,“处理器”身份识别号:“,“处理器”处理器身份识别号:“:“BMGWGGGGGGTHERMG\”,“avs-U交易的交易交易交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的身份识别识别号。身份识别号:“,,,,,,“处理器”处理器的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易的交易\“行”项目\“:null、\”状态\“:\”待结算\“、\”回复\“:\”已批准\“、\”回复代码\“:100、\”账单地址\“:{\”名字\“:”约翰\“,”姓氏\“:”Doe \“,”公司\“:\”,”地址行\“1\:\”123 一些 街道“,”地址“,”城市“:”贝塞默“,”州“:”阿尔“,”邮政编码“:”35020“,”国家“:”美国“,”电话“:”555555“,”传真“,”电子邮件“:”test@gmail.com\“},\\\\\\\\\\\\\\\\\\”:{\\\\\\\\\\\\\\\\\”,\\\\\\\\\\\\“,\\\\\\\\\\\\\”,\\\\\\\\\\\\\”,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\“邮政编码:”、“国家:”、“电话:”、“传真:”、“电子邮件:”、“创建地址:”、“2020-02-13T18:27:28.104845544Z”、“更新地址:”、“2020-02-13T18:27:28.200963331Z”、“捕获地址:”、“2020-02-13T18:27:28.2009679Z”、“无效地址:”

我收到这个信息:

System.InvalidOperationException:'无法转换类型为的对象 “System.String”至“Test.ReturnValues+Response”类型

我不确定我做错了什么。我使用一个在线json转换器来获取我的类。这似乎是正确的


有什么建议吗?

使用jsoup它是一个免费的框架,可以轻松地将文档解析为json格式

  `list<Element> news;
  Document doc = Jsoup.connect("https://en.wikipedia.org/").get();
  log(doc.title());
  Elements newsHeadlines = doc.select("#mp-itn b a");
  for (Element headline : news) {
     log("%s\n\t%s", 
   headline.attr("title"), headline.absUrl("href"));
 }`
`列出新闻;
Document doc=Jsoup.connect(“https://en.wikipedia.org/).get();
日志(doc.title());
元素NewsHeaders=doc.select(“#mp itn b a”);
for(元素标题:新闻){
日志(“%s\n\t%s”,
headline.attr(“title”)、headline.absUrl(“href”);
}`

我使用json2csharp.com生成C#类,它想出了一些不同的方法

public class ReturnValues
{
    public class Card
    {
        public string id { get; set; }
        public string card_type { get; set; }
        public string first_six { get; set; }
        public string last_four { get; set; }
        public string masked_card { get; set; }
        public string expiration_date { get; set; }
        public string response { get; set; }
        public int response_code { get; set; }
        public string auth_code { get; set; }
        public string processor_response_code { get; set; }
        public string processor_response_text { get; set; }
        public string processor_transaction_id { get; set; }
        public string processor_type { get; set; }
        public string processor_id { get; set; }
        public string avs_response_code { get; set; }
        public string cvv_response_code { get; set; }
        public object processor_specific { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
    }

    public class ResponseBody
    {
        public Card card { get; set; }
    }

    public class CustomFields
    {
    }

    public class BillingAddress
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_line_1 { get; set; }
        public string address_line_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postal_code { get; set; }
        public string country { get; set; }
        public string phone { get; set; }
        public string fax { get; set; }
        public string email { get; set; }
    }

    public class ShippingAddress
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_line_1 { get; set; }
        public string address_line_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postal_code { get; set; }
        public string country { get; set; }
        public string phone { get; set; }
        public string fax { get; set; }
        public string email { get; set; }
    }

    public class Data
    {
        public string id { get; set; }
        public string user_id { get; set; }
        public string user_name { get; set; }
        public string merchant_id { get; set; }
        public string idempotency_key { get; set; }
        public int idempotency_time { get; set; }
        public string type { get; set; }
        public int amount { get; set; }
        public int base_amount { get; set; }
        public int amount_authorized { get; set; }
        public int amount_captured { get; set; }
        public int amount_settled { get; set; }
        public int amount_refunded { get; set; }
        public int payment_adjustment { get; set; }
        public int tip_amount { get; set; }
        public string settlement_batch_id { get; set; }
        public string processor_id { get; set; }
        public string processor_type { get; set; }
        public string processor_name { get; set; }
        public string payment_method { get; set; }
        public string payment_type { get; set; }
        public List<string> features { get; set; }
        public int national_tax_amount { get; set; }
        public int duty_amount { get; set; }
        public string ship_from_postal_code { get; set; }
        public string summary_commodity_code { get; set; }
        public string merchant_vat_registration_number { get; set; }
        public string customer_vat_registration_number { get; set; }
        public int tax_amount { get; set; }
        public bool tax_exempt { get; set; }
        public int shipping_amount { get; set; }
        public int surcharge { get; set; }
        public int discount_amount { get; set; }
        public string currency { get; set; }
        public string description { get; set; }
        public string order_id { get; set; }
        public string po_number { get; set; }
        public string ip_address { get; set; }
        public string transaction_source { get; set; }
        public bool email_receipt { get; set; }
        public string email_address { get; set; }
        public string customer_id { get; set; }
        public string customer_payment_type { get; set; }
        public string customer_payment_ID { get; set; }
        public string subscription_id { get; set; }
        public string referenced_transaction_id { get; set; }
        public ResponseBody response_body { get; set; }
        public CustomFields custom_fields { get; set; }
        public object line_items { get; set; }
        public string status { get; set; }
        public string response { get; set; }
        public int response_code { get; set; }
        public BillingAddress billing_address { get; set; }
        public ShippingAddress shipping_address { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
        public string captured_at { get; set; }
        public object settled_at { get; set; }
    }

    public class RootObject
    {
        public string status { get; set; }
        public string msg { get; set; }
        public Data data { get; set; }
    }
}
公共类返回值
{
公务舱卡
{
公共字符串id{get;set;}
公共字符串卡类型{get;set;}
公共字符串first_six{get;set;}
公共字符串last_four{get;set;}
公共字符串屏蔽卡{get;set;}
公共字符串过期日期{get;set;}
公共字符串响应{get;set;}
公共int响应_代码{get;set;}
公共字符串身份验证代码{get;set;}
公共字符串处理器\u响应\u代码{get;set;}
公共字符串处理器\u响应\u文本{get;set;}
公共字符串处理器\u事务\u id{get;set;}
公共字符串处理器\u类型{get;set;}
公共字符串处理器\u id{get;set;}
公共字符串avs_响应_代码{get;set;}
公共字符串cvv_响应_代码{get;set;}
公共对象处理器_特定{get;set;}
在{get;set;}处创建的公共字符串
在{get;set;}处更新了公共字符串
}
公共类应答器
{
公共卡{get;set;}
}
公共类自定义字段
{
}
公共类计费地址
{
公共字符串first_name{get;set;}
公共字符串last_name{get;set;}
公共字符串公司{get;set;}
公共字符串地址\u行\u 1{get;set;}
公共字符串地址\u行\u 2{get;set;}
公共字符串city{get;set;}
公共字符串状态{get;set;}
公共字符串邮政编码{get;set;}
公共字符串国家{get;set;}
公用字符串电话{get;set;}
公共字符串传真{get;set;}
公共字符串电子邮件{get;set;}
}
公共类发货地址
{
公共字符串first_name{get;set;}
公共字符串last_name{get;set;}
公共字符串公司{get;set;}
公共字符串地址\u行\u 1{get;set;}
公共字符串地址\u行\u 2{get;set;}
公共字符串city{get;set;}
公共字符串状态{get;set;}
公共字符串邮政编码{get;set;}
公共字符串国家{get;set;}
公共图书馆
public class ReturnValues
{
    public class Card
    {
        public string id { get; set; }
        public string card_type { get; set; }
        public string first_six { get; set; }
        public string last_four { get; set; }
        public string masked_card { get; set; }
        public string expiration_date { get; set; }
        public string response { get; set; }
        public int response_code { get; set; }
        public string auth_code { get; set; }
        public string processor_response_code { get; set; }
        public string processor_response_text { get; set; }
        public string processor_transaction_id { get; set; }
        public string processor_type { get; set; }
        public string processor_id { get; set; }
        public string avs_response_code { get; set; }
        public string cvv_response_code { get; set; }
        public object processor_specific { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
    }

    public class ResponseBody
    {
        public Card card { get; set; }
    }

    public class CustomFields
    {
    }

    public class BillingAddress
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_line_1 { get; set; }
        public string address_line_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postal_code { get; set; }
        public string country { get; set; }
        public string phone { get; set; }
        public string fax { get; set; }
        public string email { get; set; }
    }

    public class ShippingAddress
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_line_1 { get; set; }
        public string address_line_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postal_code { get; set; }
        public string country { get; set; }
        public string phone { get; set; }
        public string fax { get; set; }
        public string email { get; set; }
    }

    public class Data
    {
        public string id { get; set; }
        public string user_id { get; set; }
        public string user_name { get; set; }
        public string merchant_id { get; set; }
        public string idempotency_key { get; set; }
        public int idempotency_time { get; set; }
        public string type { get; set; }
        public int amount { get; set; }
        public int base_amount { get; set; }
        public int amount_authorized { get; set; }
        public int amount_captured { get; set; }
        public int amount_settled { get; set; }
        public int amount_refunded { get; set; }
        public int payment_adjustment { get; set; }
        public int tip_amount { get; set; }
        public string settlement_batch_id { get; set; }
        public string processor_id { get; set; }
        public string processor_type { get; set; }
        public string processor_name { get; set; }
        public string payment_method { get; set; }
        public string payment_type { get; set; }
        public List<string> features { get; set; }
        public int national_tax_amount { get; set; }
        public int duty_amount { get; set; }
        public string ship_from_postal_code { get; set; }
        public string summary_commodity_code { get; set; }
        public string merchant_vat_registration_number { get; set; }
        public string customer_vat_registration_number { get; set; }
        public int tax_amount { get; set; }
        public bool tax_exempt { get; set; }
        public int shipping_amount { get; set; }
        public int surcharge { get; set; }
        public int discount_amount { get; set; }
        public string currency { get; set; }
        public string description { get; set; }
        public string order_id { get; set; }
        public string po_number { get; set; }
        public string ip_address { get; set; }
        public string transaction_source { get; set; }
        public bool email_receipt { get; set; }
        public string email_address { get; set; }
        public string customer_id { get; set; }
        public string customer_payment_type { get; set; }
        public string customer_payment_ID { get; set; }
        public string subscription_id { get; set; }
        public string referenced_transaction_id { get; set; }
        public ResponseBody response_body { get; set; }
        public CustomFields custom_fields { get; set; }
        public object line_items { get; set; }
        public string status { get; set; }
        public string response { get; set; }
        public int response_code { get; set; }
        public BillingAddress billing_address { get; set; }
        public ShippingAddress shipping_address { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
        public string captured_at { get; set; }
        public object settled_at { get; set; }
    }

    public class RootObject
    {
        public string status { get; set; }
        public string msg { get; set; }
        public Data data { get; set; }
    }
}