【发布时间】:2019-05-25 15:17:51
【问题描述】:
我一直在尝试使用 Windows Forms 应用程序上的 FireSharp 从 Firebase 数据库中检索所有数据,我想将其转换为自定义列表,但是当我这样做时,它给了我一个例外。
我尝试了几乎所有可能的方法,我的目标是获得这样的数据:
用户: 12345: 名称:“乔治” 姓氏:“Gigauri” 234213: 名称:“尼卡” 姓氏:“Gigauri”
作为:
12345, 234213 所以我稍后会检索他们的对象(如姓名,姓氏)。我正在使用代码:
private async void checkUser()
{
FirebaseResponse response = await client.GetAsync("Users");
List<Data> list = JsonConvert.DeserializeObject<List<Data>>(response.ToJson());
}
它给了我一个例外:
Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ConnectServer.Data]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'Body', line 1, position 8.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at ConnectServer.Form1.<checkUser>d__10.MoveNext() in D:\Microsoft Visual Studio\Projects\ConnectServer\ConnectServer\Form1.cs:line 101
【问题讨论】:
标签: c# .net windows winforms firebase