c#json操作

 引用中 增加 system.web.Extension; 和system.web.services ;

 json 转对象

private T scriptDeserialize(string jsonstr)
{
   JavaScriptSerializer js = new JavaScriptSerializer();
   return js.Deserialize(jsonstr);
}

 

对象转json

private string getJsonStr(JsonSendPlayback jsplaybcak)
{
    JavaScriptSerializer js = new JavaScriptSerializer();
     Dictionary drow = new Dictionary();
   drow.Add("videoId", jsplaybcak.VideoId);
   drow.Add("mobId", jsplaybcak.MobId);
   drow.Add("nodeId", jsplaybcak.NodeId);
   drow.Add("highPriority", jsplaybcak.HighPriority.ToString());
   drow.Add("overwrite", jsplaybcak.Overwrite.ToString());
   drow.Add("profile", jsplaybcak.Profile);
   drow.Add("ProcessName", jsplaybcak.ProcessName);
   drow.Add("device", jsplaybcak.Device);
   return js.Serialize(drow);
}

转载于:https://www.cnblogs.com/ssjsk/p/9073102.html

你可能感兴趣的:(json)