Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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创建调用服务的请求结构#_C#_Json - Fatal编程技术网

C# 如何使用C创建调用服务的请求结构#

C# 如何使用C创建调用服务的请求结构#,c#,json,C#,Json,这是我的密码 public class DetailRequest { public DetailRequest(string IDs, string Names, string Amounts) { REQDTL = new List<Detail>(); Detail detail = new Detail(); detail.ID = IDs; detail.NAME = Names;

这是我的密码

public class DetailRequest
{
    public DetailRequest(string IDs, string Names, string Amounts)
    {   
        REQDTL = new List<Detail>();
        Detail detail = new Detail();
        detail.ID = IDs;
        detail.NAME = Names;
        detail.AMOUNT = Amounts; 
        REQDTL.Add(detail);
    }
    public List<Detail> REQDTL { get; set; }
    public class Detail
    {
        [Description("ID")]
        public string ID { get; set; }
        [Description("NAME")]
        public string NAME { get; set; }
        [Description("AMOUNT")]
        public string AMOUNT { get; set; }
    }
}
但我想请求如下结构

{
   "REQDTL":[
      {
         "ID":"148488",
         "NAME":"Test1",
         "AMOUNT":"500"
      },
      {
         "ID":"148489",
         "NAME":"Test2",
         "AMOUNT":"600"
      },
      {
         "ID":"148486",
         "NAME":"Test3",
         "AMOUNT":"700"
      }
   ]
}

我认为您应该修改
DetailRequest
构造函数:

public DetailRequest(string IDs, string Names, string Amounts)
{
    REQDTL = IDs.Split(',').Zip(Names.Split(','), (id, name) => new {id, name})
        .Zip(Amounts.Split(','), (x, amount) => new Detail
        {
            ID = x.id,
            NAME = x.name,
            AMOUNT = amount
        }).ToList();
}    
用法


请粘贴不带转义符号的正确json。我们不是机器。更新的json没有转义符号,请协助。
{
   "REQDTL":[
      {
         "ID":"148488",
         "NAME":"Test1",
         "AMOUNT":"500"
      },
      {
         "ID":"148489",
         "NAME":"Test2",
         "AMOUNT":"600"
      },
      {
         "ID":"148486",
         "NAME":"Test3",
         "AMOUNT":"700"
      }
   ]
}
public DetailRequest(string IDs, string Names, string Amounts)
{
    REQDTL = IDs.Split(',').Zip(Names.Split(','), (id, name) => new {id, name})
        .Zip(Amounts.Split(','), (x, amount) => new Detail
        {
            ID = x.id,
            NAME = x.name,
            AMOUNT = amount
        }).ToList();
}    
var entity = new DetailRequest("148488,148489,148486", "Test1,Test2,Test3", "500,600,700");
var res = JsonConvert.SerializeObject(entity);