gpt4 book ai didi

c# - 在 C# 中将对象转换为 Json 并通过 POST 发送它会导致对象损坏?

转载 作者:搜寻专家 更新时间:2023-10-31 22:52:41 24 4
gpt4 key购买 nike

在 C# 上,我正在打印发送到控制台的 JSONified 字符串,它显示为

 { "message" : "done", "numSlides" : 1, "slides" : [{ "num" : 1, "key" : "530d8aa855df0c2d269a5a5853a47a469c
52c9d83a2d71d9/1slide/Slide1_v8.PNG" }], "bucket" : "xx.xxxxxxxxxx", "error"
: null, "wedge" : false, "tenant" : null, "name" : null }

然后我这样做是为了将它转换为字节数组并发送

WebRequest request = WebRequest.Create(Program.api +"/"+ route);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

//Get the request stream
Stream dataStream = request.GetRequestStream();
byte[] byteArray = Encoding.UTF8.GetBytes(myString);
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

在 node.js 方面,我在 console.logging res.body 时得到这个:

{ '{ "message" : "done", "numSlides" : 1, "slides" : ': { '{ "num" : 1, "key" : "530d8aa855df0c2d269a5a5853a47a469c52c9d83a2d71d9/1slide/Slide1_v8.PNG" }], "bucket" : "xx.xxxxxxxxxx", "error" : null, "wedge" : false, "tenant" : null, "name" : null ': '' } }

这看起来不像是有效的 JSON。发生了什么?如何发送和接收正确的数据?

最佳答案

我在测试我正在编写的 Node 服务器时遇到了类似的问题。问题最终与请求的内容类型有关。我相信这也可能是您的问题。

我在想你想要的内容类型是“application/json”。

参见 This Post了解更多信息

关于c# - 在 C# 中将对象转换为 Json 并通过 POST 发送它会导致对象损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24960483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com