首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

json字符串反序列化成种的集合

2013-01-19 
json字符串反序列化成类的集合如题json字符串如下:string JsonStr @[{PlanId:201212170001,T

json字符串反序列化成类的集合
如题
json字符串如下:
string JsonStr = @"[{""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""}]";

我新建了一个实体类,想读取这些数据,然后放到集合中。试了好几个方法都不行,基本都报错。  单引号就可以,双引号就不行了。但传递的json格式已经规定好了,就是这样的。


求解决方案。json字符串反序列化成种的集合
[解决办法]

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

public static List<T> JSONStringToList<T>(string JsonStr)
        {
            JavaScriptSerializer Serializer = new JavaScriptS……

正确的
"[{""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""}]";

把这两部分贴到能显示半角全角的编辑器中看看区别。空格和全角都有

热点排行