wp7–JSON parsing

I’m writing this mainly as a central place to store this code as I need to use it frequently – hopefully it will help others also.

Supposing I have a web service that I want to call that returns me some JSON data. I want to get that from the service and into a class which I will use as a domain model in my application. The first thing to do is to make sure that we understand the hierarchy that the JSON data represents. So for example,

{ IsSuccess: true }

is an object with a boolean property ‘IsSuccess’ which in this case is true. So we can read the {}’s as enclosing an object.

[{ IsSuccess: true },{ IsSuccess: false }]

This represents an array of objects; read the []’s as enclosing an array.

I can interpret this as an object with a property ‘FleetsCollection’ which is a list of objects which have further properties. In fact, if you take your JSON string data you can convert it to a c# class using this online tool http://json2csharp.com/