Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
4.11/5 (2 votes)
See more:
I have this JSON Data :

HTML
{"case_statuses":{"":"Choose Case Status","1":"1-Request Initiated","2":"2-In Progress","3":"3-Pending Internal","4":"4-Pending External","5":"5-Cancelled","6":"6-Closed"},"case_types":{"":"Choose Case Type","9":"Administrative","1":"Civil","3":"Commercial","2":"Criminal","12":"Expert Case","10":"IP","5":"Labor","4":"Other","13":"Outlook-Add-In","6":"Real Estate","8":"Rent Dispute","7":"Sharia\/Legacy"},"provider_groups":{"":"--","1":"Legal Department","2":"Legal Team 1","3":"Legal Team 2"}}


How I can deserialize this please ?
Posted
Updated 13-Aug-14 4:44am
v2

Hi,

Use JSON.Net Link : http://james.newtonking.com/json[^]

How to desalinize JSON using JSON.Net

C#
string json = @"{
  'Name': 'Bad Boys',
  'ReleaseDate': '1995-4-7T00:00:00',
  'Genres': [
    'Action',
    'Comedy'
  ]
}";

Movie m = JsonConvert.DeserializeObject<Movie>(json);

string name = m.Name;


This example you will find at above mentioned link.

but now very careful about culture information in JSON. If you serialize and Deserialize with same application then that's not a problem but if not then provide additional settings.

C#
//Serialize 
TestType ObjGraph=new TestType();
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(ObjGraph,typeof(TestType), new Newtonsoft.Json.JsonSerializerSettings()
            {
                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat,
                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local,
            });

//Deserialize
TestType Obj = null; //= default(T);

            Obj = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString , typeof(TestType),
                new Newtonsoft.Json.JsonSerializerSettings()
                {
                    DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat,
                    DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local
                   
                });


Enjoy :)
 
Share this answer
 
v2
Comments
Member 10872485 14-Aug-14 8:30am    
Thank you Suvabrata Roy :)
Suvabrata Roy 14-Aug-14 8:37am    
Please mark as answer which one you think most preferable for you and close it...
example: HERE[^] or HERE[^].
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-Aug-14 10:54am    
Unfortunately, those answers are not good enough and they not even address OP's problem. Serialization is good when the data is both serialized and serialized, but what to do if the JSON string and its structure is already given? This is not so trivial problem.

Please see my answer. At least I tried to explain how it works and how to practically approach to the problem.

—SA
Please see my recent answer: How To Convert object type to C# class object type[^].

And also this one, based on the above: how to conver multi level json data to C# Object?[^].

—SA
 
Share this answer
 
v2
Comments
Member 10872485 14-Aug-14 3:16am    
Thank you Sergey Alexandrovich for your ansawer, but untill now I can't understand how to deserialize my JSON array data in c#, can you give me an exemple of code how to do this please ?
Sergey Alexandrovich Kryukov 14-Aug-14 6:32am    
How about the code sample I already created?
—SA
Member 10872485 14-Aug-14 8:11am    
Sorry, but I could not understand how I can link your answer to my problem ?
Sergey Alexandrovich Kryukov 14-Aug-14 8:14am    
And I cannot understand what you cannot link. This is your question; and this is you who is interested in solving this problem, so, isn't that you who needs to explain what you fail to understand? How about trying to deserialize it based on my existing sample and then trying to explain what causes the difficulty?
—SA
Member 10872485 14-Aug-14 8:26am    
Excuse me, you're right, I tried at first but I was able to solve the problem.
Anyway, I want to try again :)
Thank you.
Hi, follow bellow link for Serialize and deserialize JSON in C#
It will definitely give you a clear idea.

http://philcurnow.wordpress.com/2013/12/29/serializing-and-deserializing-json-in-c/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900