Deserializing a JSON file with JavaScriptSerializer()

后端 未结 6 1857
醉梦人生
醉梦人生 2020-12-01 17:30

the json file\'s structure which I will deserialize looks like below;

{
    \"id\" : \"1lad07\",
    \"text\" : \"test\",
    \"url\" : \"http:\\/\\/twitpic.         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 18:29

    //Page load starts here
    
    var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new
    {
        api_key = "my key",
        action = "categories",
        store_id = "my store"
    });
    
    var json2 = "{\"api_key\":\"my key\",\"action\":\"categories\",\"store_id\":\"my store\",\"user\" : {\"id\" : 12345,\"screen_name\" : \"twitpicuser\"}}";
    var list = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(json);
    var list2 = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(json2);
    
    string a = list2.action;
    var b = list2.user;
    string c = b.screen_name;
    
    //Page load ends here
    
    public class FooBar
    {
        public string api_key { get; set; }
        public string action { get; set; }
        public string store_id { get; set; }
        public User user { get; set; }
    }
    
    public class User
    {
        public int id { get; set; }
        public string screen_name { get; set; }
    }
    

提交回复
热议问题