用JSON序列化和反序列化的类就行了,再说,JSON用单引号较好。

解决方案 »

  1.   


    public static List<T> JSONStringToList<T>(string JsonStr)
            {
                JavaScriptSerializer Serializer = new JavaScriptSerializer();            List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);            return objs;
            }
    我用了这个反序列化的方法,但是报错:
    输入的对象无效。应该是“:”或“}”
      

  2.   


    json格式不是双引号才正规么?
    单引号我也想啊,但是我只是接收json而已,格式是那边定的
      

  3.   

    string JsonStr = @" 和最后一个 " 去掉试试。
      

  4.   


            /// <summary>
            /// JSON反序列化
            /// </summary>
            public static T JsonDeserialize<T>(string jsonString)
            {            //将"yyyy-MM-dd HH:mm:ss"格式的字符串转为"\/Date(1294499956278+0800)\/"格式            string p = @"\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}";            MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertDateStringToJsonDate);            Regex reg = new Regex(p);            jsonString = reg.Replace(jsonString, matchEvaluator);            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
                {
                    T obj = (T)ser.ReadObject(ms);
                    return obj;
                }
            }
            /// <summary>
            /// 将时间字符串转为Json时间
            /// </summary>
            private static string ConvertDateStringToJsonDate(Match m)
            {            string result = string.Empty;            DateTime dt = DateTime.Parse(m.Groups[0].Value);            dt = dt.ToUniversalTime();            TimeSpan ts = dt - DateTime.Parse("1970-01-01");            result = string.Format("\\/Date({0}+0800)\\/", ts.TotalMilliseconds);            return result;        }调用   JsonDeserialize<model>(json字符串);
      

  5.   

    using System.Web.Script.Serialization;
    using System.Runtime.Serialization.Json;
     
    public static T JsonDeserialize<T>(string jsonString)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
            {
                return (T)ser.ReadObject(ms);
            }
        }
     
     
         
        List<model> list = JsonDeserialize<List<model>>(str);
      

  6.   

    如果JSON中出现时间类型 。你这个解析通过不了的!
      

  7.   

    正确的"[{""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"",""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""},
    {""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"",""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""},
    {""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"",""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""}]"
    你的错误的
    "[{""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"" ,""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""},{""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"" ,""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""},{""PlanId"":""201212170001"",""Type"":""Cable"",""PlanContentId"":""9"",""InspectGroupId"":""3"" ,""InspectContentId"":""1"",""InspectContentValue"":""XXX"",""Longitude"":""120.2113312"",""Latitude"":""30.123123"",""InspectDate"":""20121217100330"",""UserId"":""1""}]";
    把这两部分贴到能显示半角全角的编辑器中看看区别。空格和全角都有
      

  8.   

     var ary = Regex.Matches(JsonStr, @"{""PlanId"":""(?<PlanId>[^""']+)"",""Type"":""(?<Type>[^""']+)"",""PlanContentId"":""(?<PlanContentId>[^""']+)"",""InspectGroupId"":""(?<InspectGroupId>[^""']+)"" ,""InspectContentId"":""(?<InspectContentId>[^""']+)"",""InspectContentValue"":""(?<InspectContentValue>[^""']+)"",""Longitude"":""(?<Longitude>[^""']+)"",""Latitude"":""(?<Latitude>[^""']+)"",""InspectDate"":""(?<InspectDate>[^""']+)"",""UserId"":""(?<UserId>[^""']+)""}").OfType<Match>().Select(t => new
                {
                     PlanId = t.Groups["PlanId"].Value,
                    Type = t.Groups["Type"].Value,
                    PlanContentId = t.Groups["PlanContentId"].Value,
                    InspectGroupId = t.Groups["InspectGroupId"].Value,
                    InspectContentId = t.Groups["InspectContentId"].Value,
                    InspectContentValue = t.Groups["InspectContentValue"].Value,
                    Longitude = t.Groups["Longitude"].Value,
                    Latitude = t.Groups["Latitude"].Value,
                    InspectDate = t.Groups["InspectDate"].Value,
                    UserId = t.Groups["UserId"].Value
                }).ToArray();
      

  9.   

    var ary = Regex.Matches(JsonStr, @"(?<={)[^}]+(?=})").OfType<Match>().Select(t =>
                    {
                        Dictionary<string, string> dict = new Dictionary<string, string>();
                        foreach (var m in Regex.Matches(t.Value, @"[""']([^""']+)[""']:[""']([^""']+)[""'](?=,|})").OfType<Match>().Select(tt =>
                                      new
                                  {
                                      key = tt.Groups[1].Value,
                                      value = tt.Groups[2].Value
                                  }))
                            dict.Add(m.key, m.value);
                        return dict;
                    }).ToArray();
      

  10.   

    你用错类了,是 DataContractJsonSerializer类。
      

  11.   

    提问#9楼private static string ConvertDateStringToJsonDate(Match m) 
    参数有什么作用?
      

  12.   

    json序列化反序列化插件-json2.js 介绍和使用 
    http://www.suchso.com/UIweb/json2-js-stringify-parse-serializable-deserialize.html