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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值