日期:2014-05-17  浏览次数:21030 次

C#乘反序列化json字符
现在有这个字符
[{"TaskRoleSpaces":"","TaskRoles":"","ProxyUserID":"10b1c1d902044407badc39f0800db13e","UserID":"10b1c1d902044407badc39f0800db13e","UserName":"姓名","UserSystemName":"123456","OperationName":"送项目经理","OperationValue":"同意","OperationValueText":"","SignDate":"2013-11-04 17:15:34","Comment":"同意","FormDataHashCode":"","SignatureDivID":""}]

想获取到里面一些属性的值,如何弄,只写过js

------解决方案--------------------
http://www.bejson.com/go.php?u=http://www.bejson.com/index.php
先到这个网站将你的json字符串格式化,然后对照着写一个实体类,一个个字段与之对应好,然后再使用下面的方法将字符串反序列化化为这个实体类。
/// <summary>
        /// Json反序列化
        /// </summary>
        /// <param name="xmlString"></param>
        public static T Deserialize<T>(string jsonString)
        {
            T t = default(T);
            try
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                Object obj = serializer.ReadObject(stream);
                t = (T)obj;
                return t;
            }
            catch
            {
                return t;
            }
        }