views:

420

answers:

2

How can i use data in my .NET app that is coming in google's visualisation api json format? Can't imagine at the moment how to use this data.

Do i have to parse the json to an object by myself? Can i use Json.NET to deserialize it? For now i have no idea how start with this. Any help is appreciated.

Data looks like this:

{
  cols: [
    {id: '1', label: 'Name', type: 'string'},
    {id: '2', label: 'Age', type: 'number'},
    {id: '3', label: 'Birthdate', type: 'date'}
  ],
  rows: [
    {c:[{v: 'Dan'}, {v: 18.0, f: 'eighteen'}, {v: new Date(2008, 1, 28, 0, 31, 26), f: '2/28/08 12:31 AM'}]},
    {c:[{v: 'Frank'}, {v: 19.0, f: 'nineteen'}, {v: new Date(2008, 2, 30, 0, 31, 26), f: '3/30/08 12:31 AM'}]},
    {c:[{v: 'Esther'}, {v: 20.0, f: 'twenty'}, {v: new Date(2008, 3, 30, 0, 31, 26), f: '4/30/08 12:31 AM'}]}
  ]
}
+2  A: 

Can i use Json.NET to deserialize it?

Yes. That's what it's for.

For now i have no idea how start with this. Any help is appreciated.

The manual

Joe Gauterin
thank you for the answer. i forgot to mention that i'm pretty new to .NET. I read the manual and tried to figure out how to deserialize my data structure. But for now i'm more confused than before reading the manual.
pantarhei
+1  A: 

You can use Json deserialisation via the DataContractJsonSerializer class in the System.Runtime.Serialization.Json namespace. It's pretty similar to XML Serialisation in that you create a bunch of data classes, dress them with attributes and chuck the Json into a deserializer.

The article below explains how work with Json with a Google web search example:

http://www.ben-morris.com/google-search-api-deserialize-json-output-net

John P