[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Deserialize the following in c#

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 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