Solved

Deserialize the following in c#

Posted on 2014-04-08
4
154 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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