cgreathouse
cgreathouse

Reputation: 33

JSON.NET without classes

I have a component that acts as a middle man between 2 web services. Both of them communicate using JSON.

The data that goes back and forth from the web services is very similar. However, it does need to be massaged a little.

I currently have this working by deserializing the JSON, build a new JObject and serialize it. It seems like there should be better way.

I'm looking at JsonConvert, JsonConverter, JsonSerializer, JsonReader, etc. trying to see if there's a better way to do this.

Any guidance on what classes to use/override to make this process more efficent?

Thanks!

Upvotes: 0

Views: 47

Answers (1)

Fabio Salvalai
Fabio Salvalai

Reputation: 2509

You can write a custom JsonConverter using the approach described in the documentation, so you'll only have one concrete class, but this class can translate to a slightly different JSON representation of your object.

Another, more verbose, blog post about writing custom JsonConverters can be found here: http://blog.maskalik.com/asp-net/json-net-implement-custom-serialization/

Upvotes: 1

Related Questions