Parsing json objects

前端 未结 7 701
Happy的楠姐
Happy的楠姐 2020-12-09 20:51

I\'m having trouble understanding how to parse JSON string into c# objects with Visual .NET. The task is very easy, but I\'m still lost... I get this string:



        
7条回答
  •  佛祖请我去吃肉
    2020-12-09 21:25

    If you're using .NET 4 - use the dynamic datatype.

    http://msdn.microsoft.com/en-us/library/dd264736.aspx

    string json = "{ single_token:'842269070', username: 'example123', version:1.1}";
    
         JavaScriptSerializer jss = new JavaScriptSerializer();
    
         dynamic obj = jss.Deserialize(json);
    
         Response.Write(obj["single_token"]);
         Response.Write(obj["username"]);
         Response.Write(obj["version"]); 
    

提交回复
热议问题