因此,我试图借助WebRequest从Firebase在线数据库中获取对象列表,效果很好,但是当我尝试使用orderyBy =“ Price”&startAt = 2查询它时,请求将给出我有一个400错误,我不明白为什么。这是代码
private static string url = "https://project-name.firebaseio.com/Services.json?orderBy=\"Price\"&startAt=2";
public static async Task<List<Service>> GetServices()
{
List<Service> services = new List<Service>();
JObject j;
var request = WebRequest.CreateHttp(url.ToString());
request.Method = "GET";
request.ContentType = "application/json";
using (var response = await request.GetResponseAsync())
{
var json = (new StreamReader(response.GetResponseStream()).ReadToEnd());
dynamic deserialized = JsonConvert.DeserializeObject(json);
j = (Newtonsoft.Json.Linq.JObject)(deserialized);
try
{
foreach (System.Collections.Generic.KeyValuePair<string, Newtonsoft.Json.Linq.JToken> obj in j)
{
Service s = JsonConvert.DeserializeObject<Service>(obj.Value.ToString());
services.Add(s);
}
return services;
}
catch (NullReferenceException exception)
{
return new List<Service>();
}
}
}
请帮助!
答案 0 :(得分:0)
我设法解决了该错误,显然我应该做的是编辑Firebase Realtime Databse的规则以使其具有index.On属性。对于遇到此错误的任何人,请注意