0

I am trying to deserialize JSON from a Web service to a complex object in Silverlight using the DataContractJsonSerializer. When the JSON data is minimal, I am having no issues but when the data is large, I am getting SerializationException with the message " ' is not a valid JSON primitive. This error can also occur when extraneous data is present after the JSON data."

DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(MyComplexObject));

MyComplexObject object= (MyComplexObject)jsonSerializer.ReadObject(e.Result);

How do I get around this error without having to limit the size of JSON data transferred

dbc
  • 104,963
  • 20
  • 228
  • 340
  • This seems to indicate that there are invalid characters *after* the closing `}` of the JSON file. It doesn't mean you have to shorten it - just that there is invalid data. Try to investigate the JSON file you are receiving. – jcoppens Jun 29 '15 at 18:27
  • Can you give an example of the JSON causing this to break? – Devin H. Jun 29 '15 at 19:02
  • I am actually consuming a MVC Action URI in my Silverlight application. The MVC app serializes a complex object and converts it into JSON. The deserialization works when the number of complex records serialized is around 4000 but when it goes beyond that, the aforementioned error occurs. I have a sample JSON for a single object, but its too long to put it here. I will post it in the next comment. – Syam Mohan Jun 29 '15 at 19:27
  • Sample JSON {"ID":1606167,"TxnDate":"\/Date(1430280000000)\/","Date":null,"Month":{"MonthNumber":6,"MonthName":""},"Year":2015,"GC":2154.0000,"AP":false,"Caller":{"ID":657,"Name":"SampleName"},"Customer":{"ID":28,"Name":"Sample Customer","CallerFk":null},"BS":{"ID":1,"Name":"ABCD"},"Sec":null,"SecName":"Sample 1","Months":6,"CustomerFK":28,"CallerFK":657,"BS":"B","CustName":"Sample Name 3","CallerName":Sample Name 4","CatalystFK":null}, – Syam Mohan Jun 29 '15 at 19:30

0 Answers0