I have this class as object to serialize:
public class JsonServerToClient
{
public JsonServerToClient()
{
query = new List<Query>();
}
public String authKey { get; set; }
public List<Query> query { get; set; }
public struct Query
{
public int error { get; set; }
public DataTable result { get; set; }
}
}
I use JsonConvert.SerializeObject(objectAbove); to serialize JSON.
and JsonConvert.DeserializeObject<JsonServerToClient>(text); to deserialize it.
All works fine when the result is full of data, but if it is null I get this JSON:
{
"authKey": "pippo",
"query": [
{
"error": -1,
"result": null
}
]
}
The problem is when I try to deserialize this I get an exception:
Eccezione non gestita di tipo 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll
Ulteriori informazioni: Unexpected end when deserializing array. Path '', line 1, position 56.