2012-06-07 101 views
0

這是我的JSON的結構:反序列化字符串數組WP7

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} 
     }]"; 

我想反序列化回我的類的對象數組。任何人都可以幫我解決這個問題嗎?我想最好使用datacontractjsonserializer,但其他人也很好。

感謝你

+0

看看http://stackoverflow.com/questions/8201971/deserializing-json-in-wp7 – Tamkeen

回答

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;  
    } 
相關問題