我有这段代码用于将我的 JSON 字符串放在 Firebase 数据库上:

RestRequest request = new RestRequest("MemberAndChannels/{userId}/{channelId}.json", Method.POST);

request.RequestFormat = DataFormat.Json;
request.AddParameter("auth", accessKey);
request.AddUrlSegment("userId", user.UUID);
request.AddUrlSegment("channelId", channel.UUID);
request.AddHeader("Content-Type", "application/json; charset=utf-8");

request.AddJsonBody(channelJson);

IRestResponse response = client.Execute(request);

if (response.StatusCode == HttpStatusCode.OK)
{

}
else {

}

但我收到以下错误(状态代码:BadRequest):
"{\n  \"error\" : \"Invalid data; couldn't parse JSON object, array, or value.\"\n}\n"

我已经尝试使用 curl 放置相同的数据并且它起作用了。无法弄清楚我哪里做错了。

最佳答案

对象被序列化两次(双重序列化)。

channel 对象按原样传递给 AddJsonBodyrequest 将在发送正文之前将其序列化为 JSON

request.AddJsonBody(channel);

假设这里 channel 是一个类的对象

关于c# - 在 Firebase REST API 上放置 JSON 数据时出现 BadRequest,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50658583/

10-09 18:20
查看更多