Hi,

I have a jaso object that i am getting from a API access. how do i deserialize the jason object in C# so that I can get the papameter values.

JavaScriptSerializer js = new JavaScriptSerializer();
        bookshare bs = js.Deserialize<bookshare>(response);

        string a = bs.version;

when i do this for string a i get null value?

how do i solve this
appreciate a reply
thanks

Here is an example. Can you show what is in response and how the class definition of bookshare looks?

yes
the response is as below:

" {\"bookshare\": {\n \"version\": \"4.1.1\",\n \"messages\": [\n ],\n \"book\": {\n \"metadata\": {\n \"author\": [\n \"David Flanagan\"\n ],\n \"availableToDownload\": 0,\n \"bookshareId\": \"21385\",\n \"briefSynopsis\": \"The 1.4 release of Java 2 Standard edition brings a load of new features - and the potential for frustration. Fret not, our new 4th edition has answers. The accelerated introduction lets you start writing code right away, and because the book's classic quick reference contains all the classes in the essential Java packages, you can find exactly what you need to make Java's new version work for you.\",\n \"category\": [\n \"Computers and Internet\"\n ],\n \"completeSynopsis\": \"The 1.4 release of Java 2 Standard edition brings a load of new features - and the potential for frustration. Fret not, our new 4th edition has answers. The accelerated introduction lets you start writing code right away, and because the book's classic quick reference contains all the classes in the essential Java packages, you can find exactly what you need to make Java's new version work for you.\",\n \"contentId\": 21385,\n \"copyright\": \"2005\",\n \"downloadFormat\": [\n ],\n \"dtbookSize\": 6396260,\n \"freelyAvailable\": 0,\n \"images\": 0,\n \"isbn13\": \"9780596007737\",\n \"language\": [\n \"English US\"\n ],\n \"publishDate\": \"05122005\",\n \"publisher\": \"O'Reilly\",\n \"quality\": \"Publisher Quality\",\n \"title\": \"Java in a Nutshell, 5th Edition\"\n }\n }\n}}\n\n \n"

and i wrote the code as:

JavaScriptSerializer js = new JavaScriptSerializer();
        bookshare bs = js.Deserialize<bookshare>(response);

        string a = bs.version;

appreciate a reply
thanks

Bookshare.cs

public class bookshare
{
   public string version { set; get;}
   public string messages { set; get;}
   public book b = new book();

    public bookshare()
    {

    }
}

book.cs

public class book
{
    public metadata m = new metadata();

    public book()
    {

    }
}

metadata.cs

public class metadata
{
    public string author { get; set; }
    public string availableToDownload { get; set; }
    public string bookshareId { get; set; }
    public string breifSynopsis { get; set; }
    public string category { get; set; }
    public string completeSynopsis { get; set; }
    public string contentId { get; set; }
    public string copyright { get; set; }
    public string downloadFormat { get; set; }
    public string dtbookSize { get; set; }
    public string freelyAvailable { get; set; }
    public string images { get; set; }
    public string isbn13 { get; set; }
    public string language { get; set; }
    public string publishDate { get; set; }
    public string publisher { get; set; }
    public string quality { get; set; }
    public string title { get; set; }

    public metadata()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}

these are the class definitions.
not sure y i am getting null values

appreciate a reply
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.