bugthesystem / FireSharp

An asynchronous cross-platform .Net library for Firebase
The Unlicense
698 stars 147 forks source link

Json problem while response.ResultAs<...>() #64

Closed AurelienMarin closed 8 years ago

AurelienMarin commented 8 years ago

Hello guys, When I try to get my data with GetAsync() this message appears

{"Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[NumimaniaUI.DatabaseDiagram]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo 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) 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.\r\nPath '-KNFbTGxLeoPyNjn9fu9', line 1, position 24."}

public static async void Gett()
{
    _client = new FirebaseClient(config);
    FirebaseResponse response = await _client.GetAsync("Numimania");
    List<DatabaseDiagram> data = response.ResultAs<List<DatabaseDiagram>>();
}

And this are my data in Firebase http://puu.sh/qa7rB/450ca3cbc3.png

So if you could help me, will be great if you have a solution

(Sorry for my bad english :'( )

AurelienMarin commented 8 years ago

Okay, I found a answer

So the solution: In my case, I had to use an IDictionnary, so it looks like that

 IDictionary<string, DatabaseDiagram> data = response.ResultAs<IDictionary<string, DatabaseDiagram>>();

Thanks to http://stackoverflow.com/questions/27645952/json-net-cannot-deserialize-the-current-json-object-e-g-namevalue-in