0

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

2
Contributors
4
Replies
13
Views
4 Years
Discussion Span
Last Post by anisha.silva
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.