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

高分求一正则表达式,取得如下内容
{"nu":"568452066234","message":"ok","ischeck":"0","com":"shentong","updatetime":"2012-12-06 16:02:50","status":"200","condition":"J1000","data":[{"time":"2012-12-02 18:59:27","context":"【河北衡水公司】已进行【疑难件】扫描 ,疑难件原因:【问题件请联系发件公司】","ftime":"2012-12-02 18:59:27"},{"time":"2012-12-02 10:56:19","context":"【河北衡水公司】的派件员【孙金艳18931821871 手机(18931821871)】正在派件","ftime":"2012-12-02 10:56:19"},{"time":"2012-12-02 09:52:34","context":"快件已到达【河北衡水公司】 扫描员是【兰瑞琴】上一站是【】","ftime":"2012-12-02 09:52:34"},{"time":"2012-12-01 06:56:53","context":"由【河北石家庄中转部】发往【河北衡水公司】","ftime":"2012-12-01 06:56:53"},{"time":"2012-11-29 04:03:03","context":"快件已到达【浙江杭州航空部】 扫描员是【称重2】上一站是【】","ftime":"2012-11-29 04:03:03"},{"time":"2012-11-29 04:01:03","context":"由【浙江杭州航空部】发往【河北石家庄中转部】","ftime":"2012-11-29 04:01:03"},{"time":"2012-11-29 04:01:03","context":"【浙江杭州航空部】正在进行【装车】扫描","ftime":"2012-11-29 04:01:03"},{"time":"2012-11-28 19:46:41","context":"【浙江椒江公司】的收件员【张利茂 】已收件","ftime":"2012-11-28 19:46:41"},{"time":"2012-11-28 18:32:43","context":"由【浙江椒江公司】发往【浙江杭州航空部】","ftime":"2012-11-28 18:32:43"}],"state":"2"}


==================================

我想取到的数据库为:
2012-12-02 18:59:27 【河北衡水公司】已进行【疑难件】扫描 ,疑难件原因:【问题件请联系发件公司】
2012-12-02 18:59:27 【河北衡水公司】的派件员【孙金艳18931821871 手机(18931821871)】正在派件
==不一一列表,也就是取日期+空格+事件+回车
------最佳解决方案--------------------
            string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
            var ary = Regex.Matches(str, @"""time"":""(?<time>[^""]+)""\s*,""context"":""(?<txt>[^""]+)""").Cast<Match>().Select(t => new { time = t.Groups["time"].Value, txt = t.Groups["txt"].Value }).ToArray();
            
------其他解决方案--------------------
这是json,不用正则,直接反序列化就可以
------其他解决方案--------------------
用json.net反序列化
------其他解决方案--------------------
引用:
这是json,不用正则,直接反序列化就可以


+1
------其他解决方案--------------------
引用:
string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
            var ary = Regex.Matches(str, @"""time"":""(?<time>[^""]+)""\s*,""context"":""(?<txt>[^""]+)""").Cast<Match>().Sel……


如何转化为Dictionary<string, string>
------其他解决方案--------------------
 Dictionary<string, string> dict = new Dictionary<string, string>();
            foreach (var t in ary)
            {
                dict.Add(t.time, t.txt);
            }
------其他解决方案--------------------
感觉没必要转为Dictionary<string, string>