Unexpected end when deserializing object

Jan 26, 2010 at 9:05 PM

 

Hi,

Using the Silverlight version of Json.Net in VS2010 and .Net 4. I am Deserializing what appears a valid Json structure (it is serialised on the server using Json.Net with TypeNameHandling.All.

This call works correctly on the client.

JObject o = JObject.Parse(Json);

Thus I can assume the Json is not corrupted in transit.

But when I use:

var js = new JsonSerializer {TypeNameHandling = TypeNameHandling.All};                

var str = new StringReader(Json);

return js.Deserialize(new JsonTextReader(str), type);

 

I get the following exception. 

 

+ $exception {Newtonsoft.Json.JsonSerializationException: Unexpected end when deserializing object.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValue(JsonReader reader, Type objectType, JsonContract contract, Object existingValue, JsonConverter memberConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at NetworkedPlanet.Web3.Platform.Service.Client.AsyncSchemaServiceClient.Deserialize(Stream stream, Type type, Int64 contentLength)} System.Exception {Newtonsoft.Json.JsonSerializationException}

$exception {Newtonsoft.Json.JsonSerializationException: Unexpected end when deserializing object.

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, Object existingValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValue(JsonReader reader, Type objectType, JsonContract contract, Object existingValue, JsonConverter memberConverter)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)

 

Any ideas on what I am doing wrong would be most appreciated.

Graham

 

 

Coordinator
Jan 27, 2010 at 12:37 AM

Download Json.NET 3.5r6 and try again, it might have been fixed.

If it isn't then post the class and what JSON you are attempting to deserialize and I'll see what is up.

Jan 27, 2010 at 6:48 AM

Super, that fixed the issue. Many thanks for your quick reply and great work.

Graham.