Solved

Deserialize the following in c#

Posted on 2014-04-08
4
155 Views
Last Modified: 2014-04-26
I am new to deserialization using JSON, so I need to know how to create a class object that gets assigned the values from the deserialization process.  I have the following data retrieved in JSON that I would like to properly create a class and be able to throw that information into the created class.  Please help!  Thanks!

{
    "response":
     {
                  "authToken":  "webapi123431095"
     },
    "status":
     {
              "detail":
               {
               },
               "success": true
     }
}

Open in new window

0
Comment
Question by:VBBRett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 250 total points
ID: 39986799
I think this had already been addresses in a previous question :)

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28268323.html
0
 

Author Comment

by:VBBRett
ID: 39986867
Thanks, but since I am new to deserializing, do you know of a way to deserialize the string that I posted?  Thanks!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39987463
There are plenty of examples on how to do this. For instance, my comment here:

http://www.experts-exchange.com/Programming/Languages/.NET/Q_28400081.html#a39962468

The basic idea is that anywhere in your JSON that you have curly braces ( {} ), you will be creating a new class; anywhere in your JSON that you have square brackets ( [] ), you will be creating an array; everything else is just a property. You need to create a "root" class to hold the overall JSON once it's converted.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39987472
In your case, you might define a root class as:

public class ServiceResponse
{
}

Open in new window


...which will have two properties:

public class ServiceResponseModel
{
    public XXXX Response { get; set; }
    pulbic YYYY Status { get; set; }
}

Open in new window


Now, both response and status are followed by curly braces, so that means you need a new class for each:

public class ResponseModel
{
    public string AuthToken { get; set; }
}

public class StatusModel
{
    ZZZZ  // I'll let you fill in ZZZZ  = )
}

Open in new window


These new classes will be the types for the two new properties:

public class ServiceResponseModel
{
    public ResponseModel Response { get; set; }
    pulbic StatusModel Status { get; set; }
}

Open in new window


Once you fill in everything, it's just a matter of passing the data and the type information (i.e. ServiceResponseModel) to the serializer.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question