0

This is the structure of my JSON:

string sample = 
    "[{'Disp_Name':'avi garg',
       'emailId':'[email protected]',
       'fName':'avi',
       'lName':'garg',
       'ph':{'number':'9813612344(Mobile)','type':1}
      },
      {'Disp_Name':'monk gup',
       'emailId':'[email protected]',
       'fName':'monk',
       'lName':'gup',
       'ph':{'number':'01127243480(home)','type':2}
      }]";

And I want to deserialize it back to an object array of my class. Can anyone please help me out in doing that? I would like to use datacontractjsonserializer preferably but others are also fine.

Thanking you

1

1 Answer 1

1
public static List<your class> decrypt_json(string json)
    {
        var deserializedUser = new List<your class>();
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        DataContractJsonSerializer ser=new DataContractJsonSerializer(deserializedUser.GetType());
        deserializedUser =  ser.ReadObject(ms) as List<your class>;
        MessageBox.Show(deserializedUser.Count().ToString());
        ms.Close();
        return deserializedUser;       
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.