除非放在方括号中,否则Json发布无效

时间:2019-01-23 20:55:43

标签: c# json

在我的代码中,我发送了一个帖子来休息服务,例如:

zip.fp.seek(0)  # To make sure the read for write start from the beginning
with open('outfile.zip', 'wb') as outfile:
    outfile.write(zip.fp.read())

mydata集合由PostAsJsonAsyn转换为Json:

var response = await client.PostAsJsonAsync(requesturi, mydata);

但是,除非杰森对象用括号括起来(在Postman中测试),否则服务器将返回Http 400响应

{
    "queryid" : "GetNames",
    "@StartDate" : "1/1/2019",
    "@EndDate" : " "2/1/2019"
}

是否可以将方括号添加到PostAsJasonAsyn方法传递的json对象中

谢谢

2 个答案:

答案 0 :(得分:1)

尝试一下:

var response = await client.PostAsJsonAsync(requesturi, new[] { mydata } );

答案 1 :(得分:-1)

这是因为JSON的标准。您应该先在互联网上搜索:

https://jsonlint.com/

How do I turn a C# object into a JSON string in .NET?

Working With JSON in C#