0

This is the structure of my JSON:

string sample = 
    "[{'Disp_Name':'avi garg',
       'emailId':'avi@india.com',
       'fName':'avi',
       'lName':'garg',
       'ph':{'number':'9813612344(Mobile)','type':1}
      },
      {'Disp_Name':'monk gup',
       'emailId':'mon@india.com',
       '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

pb2q
  • 58,613
  • 19
  • 146
  • 147
Lokis
  • 11
  • 5

1 Answers1

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;       
    }
Jonathan Spooner
  • 7,682
  • 2
  • 34
  • 41
Lokis
  • 11
  • 5