Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c中将Json字符串转换为键值对?_C#_.net_Regex_Json_Parsing - Fatal编程技术网

C# 如何在c中将Json字符串转换为键值对?

C# 如何在c中将Json字符串转换为键值对?,c#,.net,regex,json,parsing,C#,.net,Regex,Json,Parsing,我看到这已经得到了很多反对票,但实际上没有人提出任何建议。上面的json不适合字典,但应该反序列化为对象 响应、沉降和vault都有自己的属性,因此应该是自己的对象 查看Json.net,寻找将Json转换为c对象的好方法。如果您对如何用C表示这个对象感到困惑,那么您需要阅读一本关于编程的好书,特别是一本涉及面向对象编程的书 对于这些问题,Stack是一个很好的资源,但你需要先尝试证明你已经完成了自己的研究,否则其他人只会记下你的问题 您是否收到包含JSON的帖子 您可以使用类似的方法,创建请求

我看到这已经得到了很多反对票,但实际上没有人提出任何建议。上面的json不适合字典,但应该反序列化为对象

响应、沉降和vault都有自己的属性,因此应该是自己的对象

查看Json.net,寻找将Json转换为c对象的好方法。如果您对如何用C表示这个对象感到困惑,那么您需要阅读一本关于编程的好书,特别是一本涉及面向对象编程的书


对于这些问题,Stack是一个很好的资源,但你需要先尝试证明你已经完成了自己的研究,否则其他人只会记下你的问题

您是否收到包含JSON的帖子

您可以使用类似的方法,创建请求类的实例,并将JSON obj分配给该实例。您应该能够通过请求实例访问参数

基本结构如下所示:

   {
      "transactionId" : XXXXX,
      "uri" : "https://XXX.XXXXXXXX.XXXX/XXX/XXX",
      "terminalId" : 1,
      "action" : "CHARGE",
      "amountBase" : "3.00",
      "amountTotal" : "3.00",
      "status" : "CAPTURE",
      "created" : "2015-01-24T07:24:10Z",
      "lastModified" : "2015-01-24T07:24:10Z",
      "response" : 
       {
           "approved" : true,
           "code" : "00",
           "message" : "Approved",
           "processor" : 
            {
               "authorized" : true,
               "approvalCode" : "XXXX",
               "avs" : 
                     {
                         "status" : "NOT_REQUESTED"
                     },
            }
  },
  "settlement" : 
   {
        "settled" : false
   },
  "vault" : 
   {
        "type" : "CARD",
        "accountType" : "VISA",
        "lastFour" : "1111"
  }

}

希望这有帮助

此JSON不适合键值对,即字典。您可以通过将JSON转储到中自动生成上述内容。
public class Request
{
    public Int64 transactionId { get; set; }
    public string uri { get; set; }
    public int terminalId { get; set; }
    public string action { get; set; }
    public string amountBase { get; set; }
    public int amountTotal { get; set; }
    public string status { get; set; }
    public DateTime created { get; set; }
    public DateTime lastModified { get; set; }
    public Response response { get; set; }
    public Settlement settlement { get; set; }
    public Vault vault { get; set; }
}
public class Response
{
    public bool approved { get; set; }
    public int code { get; set; }
    public string message { get; set; }
    public Processor processor { get; set; }
}
public class Processor
{
    public bool authorized { get; set; }
    public string approvedCode { get; set; }
    public AVS avs { get; set; }
}
public class AVS
{
    public string status { get; set; }
}
public class Settlement
{
    public bool settled { get; set; }
}
public class Vault
{
    public string type { get; set; }
    public string accountType { get; set; }
    public string lastFour { get; set; }
}