首页 新闻 会员 周边 捐助

有关json的问题

0
悬赏园豆:20 [已解决问题] 解决于 2012-03-23 18:20

{\"ErrorCode\":0,\"Success\":true,\"ErrMessage\":\"数据源ID:4418,错误:\",\"HasData\":true,\"Records\":[{\"Time\":\"2012-03-08 16:31:00\",\"Location\":\"中环路东二路路口\",\"Reason\":\"机动车通过有灯控路口时,不按所需行进方向驶入导向车道的\",\"count\":\"100\",\"status\":\"\",\"department\":\"\",\"Degree\":\"0\",\"Code\":\"1208\",\"Archive\":\"4401261001227283\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2012-02-24 19:09:00\",\"Location\":\"番禺大道龙美高架桥甘棠村段\",\"Reason\":\"机动车行驶超过规定时速50%以下的\",\"count\":\"150\",\"status\":\"\",\"department\":\"\",\"Degree\":\"3\",\"Code\":\"1303\",\"Archive\":\"4401261001053350\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2012-01-06 09:39:00\",\"Location\":\"莞佛高速\",\"Reason\":\"在高速公路上超速不足50%的\",\"count\":\"200\",\"status\":\"\",\"department\":\"\",\"Degree\":\"3\",\"Code\":\"4305\",\"Archive\":\"4401131000268873\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2011-12-31 11:08:00\",\"Location\":\"天科路路段\",\"Reason\":\"机动车违反禁止标线指示的\",\"count\":\"200\",\"status\":\"\",\"department\":\"\",\"Degree\":\"3\",\"Code\":\"1345\",\"Archive\":\"4401131000192363\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2011-10-15 09:20:00\",\"Location\":\"华粤街路口\",\"Reason\":\"机动车违反规定停放、临时停车,妨碍其它车辆、行人通行的\",\"count\":\"200\",\"status\":\"\",\"department\":\"\",\"Degree\":\"0\",\"Code\":\"1039\",\"Archive\":\"4401131009159332\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2011-07-03 08:12:00\",\"Location\":\"黄埔大道\",\"Reason\":\"机动车违反禁止标线指示的\",\"count\":\"200\",\"status\":\"\",\"department\":\"\",\"Degree\":\"3\",\"Code\":\"1345\",\"Archive\":\"4401131008101821\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"},{\"Time\":\"2011-06-26 13:03:00\",\"Location\":\"华就路\",\"Reason\":\"机动车违反规定停放、临时停车,妨碍其它车辆、行人通行的\",\"count\":\"200\",\"status\":\"\",\"department\":\"\",\"Degree\":\"0\",\"Code\":\"1039\",\"Archive\":\"4401131008033417\",\"Telephone\":\"\",\"Excutelocation\":\"\",\"Excutedepartment\":\"\",\"Category\":\"\",\"Latefine\":\"\",\"Punishmentaccording\":\"\",\"Illegalentry\":\"\",\"Locationid\":4401,\"DataSourceID\":4401,\"RecordType\":\"实时数据\",\"Other\":\"\"}],\"Other\":null,\"ResultType\":\"实时数据\",\"LastSearchTime\":null}

在.ashx文件里怎么把"\"去掉,或者怎样把'换成""

wlz0815的主页 wlz0815 | 小虾三级 | 园豆:587
提问于:2012-03-23 12:02
< >
分享
最佳答案
0

爲什麽去掉呢?這個是正常的 josn 數據哦。

收获园豆:5
無限遐想 | 老鸟四级 |园豆:3740 | 2012-03-23 12:10

反序列化不成功呀JsonConvert.DeserializeObject(),用它不行呀。

wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 12:15

@wlz0815:   //将Json字符串转化成对象

        DataContractJsonSerializer outDs = new DataContractJsonSerializer(typeof(Person));
        using (MemoryStream outMs = new MemoryStream(Encoding.UTF8.GetBytes(output)))
        {
            Person outPerson = outDs.ReadObject(outMs) as Person;
 
            Console.WriteLine("ID:" + outPerson.ID);
            Console.WriteLine("Name:" + outPerson.Name);
            Console.WriteLine("Age:" + outPerson.Age);
            Console.WriteLine("Birthday:" + outPerson.BirthDay);
        }
無限遐想 | 园豆:3740 (老鸟四级) | 2012-03-23 12:18

@無限遐想: 辛苦了。。

wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 18:17
其他回答(3)
0

josn 数据的格式···javascript 来读没问题的·  你可以反序列化下 就去掉了

收获园豆:5
王大湿 | 园豆:457 (菜鸟二级) | 2012-03-23 12:13

怎样写,能说具体点不,试了好久都不行,还请赐教,不慎感激。

支持(0) 反对(0) wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 12:16

嗯,谢谢,我已经解决了。

支持(0) 反对(0) wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 18:16
0

可以用正则表达式进行替换:

Regex.Replace(text, @"(?<=[{,])(\\"")|(\\"")(?=[:}])", @"""")
收获园豆:5
dudu | 园豆:30948 (高人七级) | 2012-03-23 15:34

谢谢,我已经解决了。

支持(0) 反对(0) wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 18:16
0

  /// <summary>
        /// 生成Joson字符串
        /// </summary>
        /// <param name="ti">ti</param>
        /// <returns></returns>
        public string ToJonsonString(List<TreeItem> ti)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string sJson = jss.Serialize(ti);
            return "var treedata=" + sJson + ";";
        }

收获园豆:5
hushaorenaspnet | 园豆:280 (菜鸟二级) | 2012-03-23 17:37

谢谢,解决了。

支持(0) 反对(0) wlz0815 | 园豆:587 (小虾三级) | 2012-03-23 18:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册