I'm looking for a JSON parser and encoder for .NET that can parse JSON into its own data structure which I can then navigate, as opposed to directly deserializing it into a class. In Java, I use Jettison's JSONObject and JSONArray which is dead easy to use.
There are a number of reasons why I don't want to (de)serialize:
Is there anything available or do I have to port a subset of Jettison?
The disadvantages of serialization that you point out aren't really there, at least in the case of JSON.NET:
But, if you really want to do that, you can. The equivalent types are JObject
and JArray
, so, if you want to deserialize some object, use:
JObject obj = JsonConvert.DeserializeObject<JObject>(json);
As another option, you don't have to specify the type you want at all, ant it will return either JObject
or JArray
:
object objectOrArray = JsonConvert.DeserializeObject(json);