Take the 2-minute tour ×

Possible Duplicate:
Parse JSON in C#

I'm trying to deserialize a JSON string from the openlibrary.org in an ASP.NET (4.5) web application using JSON.NET.

My aim is to be able to read the 5 properties below from a single .Net object.

The example JSON I have is:

        "bib_key": "ISBN:0201558025",
        "preview": "noview",
        "thumbnail_url": "http://covers.openlibrary.org/b/id/135182-S.jpg",
        "preview_url": "http://openlibrary.org/books/OL1429049M/Concrete_mathematics",
        "info_url": "http://openlibrary.org/books/OL1429049M/Concrete_mathematics"

I can get it to work fine without the first line, but I'm a bit lost trying to work out how I should structure my classes.

I'm new to JSON and haven't played with C#/VB.NET in a few years so getting very lost.


I have the following code:

Dim url = "http://openlibrary.org/api/books?bibkeys=ISBN:0201558025&format=json"
Dim webClient = New System.Net.WebClient
Dim json = webClient.DownloadString(url)

Dim book As Book = JsonConvert.DeserializeObject(Of Book)(json)

And the class Book:

Public Class Book
    Public bib_key As String
    Public preview As String
    Public preview_url As String
    Public info_url As String
End Class

However, book turns up empty.

share|improve this question

marked as duplicate by Jonathon Reinhart, AVD, Matthew, Donal Fellows, Graviton Dec 31 '12 at 3:00


3 Answers 3

I think it can be deserialized as a Dictionary.

new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Dictionary<string, BookInfoClass>>(jsonString);
share|improve this answer

Try using JSON.Net


JavaScriptSerializer Class


DataContractSerializer class

share|improve this answer

There is a website called json2csharp - generate c# classes from json:

public class RootObject
    public string bib_key { get; set; }
    public string preview { get; set; }
    public string thumbnail_url { get; set; }
    public string preview_url { get; set; }
    public string info_url { get; set; }

The json format is a little off, remove the {"ISBN:0201558025": since you have the ISBN as the bib_key

share|improve this answer
Thanks, I had tried that but wasn't sure about the ISBN bit. The problem I'm having now is that my book object isn't receiving the details, which lead me to think I may be missing a class. –  ataru Dec 22 '12 at 14:09
