【发布时间】:2018-06-02 15:48:36
【问题描述】:
我有这段代码用于将我的 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 输入相同的数据,并且成功了。不知道我哪里做错了。
【问题讨论】:
-
什么是
channelJson? -
您的请求有一些错误。 channelJson 是 String 还是 Json Object。?
-
channelJson 是 String 格式的 Json 对象。这就是我得到channelJson的方式: var channelJson = new JavaScriptSerializer().Serialize(channel);这里的通道是一个类的对象。
-
能否在控制台打印channelJson值并检查请求是否准备正确?
-
这里是 channelJason 的值:{\"ChannelName\":\"Best\",\"ChannelImageUrl\":\"firebasestorage.googleapis.com/v0/b/chat-demo-25252.appspot.com/…\\u0026token=3q11ac21-7414-6562-85b4- 111ffdda0047\",\"UUID\":\"24C9955C-AC97-4741-2314-5E950712A826\"}
标签: c# asp.net firebase-realtime-database restsharp