Free setup for Json.NET is similar to GSON

In GSON, you can deserialize on a JsonObject, which in turn allows you to access JsonElements and call methods like getAsString (), getAsInt (), etc.

This is incredibly useful for my use: I serialize data from JSON and send it over the network. The data is sent along with protocol identifiers that tell the client how to process the data. I don't want to create a class for every other type of protocol, so deserializing as JsonObject allows me a lot of flexibility.

I cannot find a similar way to do this in C #. I suppose I need to flip my own JsonElement / Object / Array / Primitive hierarchy, but I don't know where to start. Is this even the best way to do it?

I want to:

Deserialize json in C # into a structure that allows me to access data as specific types without using a skeleton class for the data.

EDIT:

I'm limited to .NET 3.5

+3


source to share


1 answer


JSON.NET can do this - you don't need to deserialize the class:

int value = JObject.Parse(myJsonString)["property"]["subProperty"].Value<int>();

      



See the LINQ to JSON documentation for more information .

+3


source







All Articles