JSON.Instance.ToObject<object>(string); fails in v.1.9.8

May 28, 2012 at 8:50 PM
Edited May 28, 2012 at 9:28 PM

I have two programs that has a common DLL so both programs have same classes and objects available. One program sends the JSON string over TCP/IP and the other recives.

If I tried to create object on one program make it JSON string with fastJSON and then back again it worked flawlessly. 

But if I just made the string with JSON.Instance.ToJSON(object) copied that string and tried to make the object with JSON.Instance.ToObject<object>(string) with the same string i got the following error:

System.NullReferenceException was unhandled  Message=Object reference not set to an instance of an object.

on line: 486 in JSON.cs

changed Line 61 - 67 in JSON.cs:

public object ToObject(string json, Type type)
{
	Dictionary<string, object> ht = new JsonParser(json, Parameters.IgnoreCaseOnDeserialize).Decode() as Dictionary<string, object>;
	if (ht == null) return null;
	return ParseDictionary(ht, null, type, null);
}

to:

public object ToObject(string json, Type type)
{
	_params = Parameters;
	Dictionary<string, object> ht = new JsonParser(json, Parameters.IgnoreCaseOnDeserialize).Decode() as Dictionary<string, object>;
	if (ht == null) return null;
	return ParseDictionary(ht, null, type, null);
}

Coordinator
May 29, 2012 at 4:37 AM

Thanks, nice catch.