c# json解析

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       var test = SynchronizationJson("{\"head\":{\"password\":\"aa\",\"action\":\"execute\",\"functionid\":\"subexamInfo\",\"sysid\":\"bb",\"timestamp\":\"20131211032719\",\"isdata\":\"1\"},\"parameter\":{\"userid\":\"ss\",\"exscheme\":[{\"answer\":\"00002\",\"id\":\"F\"}],\"telphone\":\"tt\",\"id\":\"B0E99FB0-BB21-4A64-ACC8-D5B0BC75DB5E\"}}"
);
    }
        public static IDictionary<string, string> SynchronizationJson(string json)
        {
            try
            {
                IDictionary<string, string> dict = new Dictionary<string, string>();
                JavaScriptSerializer js = new JavaScriptSerializer();
                DataJsonSet Json = js.Deserialize<DataJsonSet>(json);
                dict.Add("sysid", Json.head.sysid);
                dict.Add("sysaccount", Json.head.functionid);
                dict.Add("syspassword", Json.head.password);
                return dict;
            }
            catch (Exception ex)
            {
                IDictionary<string, string> dict = new Dictionary<string, string>();
                dict.Add("error", "Json解析错误!" + ex.Message);
                return dict;
            }
        }
    }

    [Serializable]
    public class DataJsonSet
    {
        public head head { get; set; }
        public parameter parameter { get; set; }
    }
    [Serializable]
    public class head
    {
        public string sysid { get; set; }
        public string password { get; set; }
        public string timestamp { get; set; }
        public string functionid { get; set; }
        public string action { get; set; }
    }

    [Serializable]
    public class parameter
    {
        public string id { get; set; }
        public string userid { get; set; }
        public exscheme[] exscheme { get; set; }
    }

    [Serializable]
    public class exscheme
    {
        public string id { get; set; }
        public string answer { get; set; }
    }

你可能感兴趣的:(c# json解析)