?
Solved

Deserialize the following in c#

Posted on 2014-04-08
4
Medium Priority
?
156 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 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