public static void PraseHistoryData() { var all = FindAll(); int index = 1; Parallel.For(0, all.Count, new ParallelOptions() { MaxDegreeOfParallelism = 1 }, i => { XTrace.WriteLine("进度:{0}/{1}", index++, all.Count); #region 单个文本解析 JsonParser jp = new JsonParser(all[i].HisText); var decode = (List <object>)jp.Decode(); if (decode.Count < 1) { return; } var main = (Dictionary <string, object>)decode[0];//字典 if (main.ContainsKey("hq")) { var obj = (List <object>)main["hq"]; if (obj.Count > 0) { List <StockDayData> res = new List <StockDayData>(); foreach (var item in obj) { #region 单条记录解析 //item是一个10个元素的数组 //日期,今开价格,今天收盘价格,涨跌金额,涨跌幅度,最低价格,最高价格,总手,总金额(万),换手率 //"2018-02-09", "31.46", "31.46", "2.86", "10.00%", "31.46", "31.46", "303", "95.32", "0.15%" var list = (List <object>)item; StockDayData sd = new StockDayData() { Code = all[i].Code, StatDate = list[0].ToDateTime(), StartPrice = list[1].ToDouble(), EndPrice = list[2].ToDouble(), ChangePrice = list[3].ToDouble(), ChangeRatio = ((string)list[4]).Replace("%", "").ToDouble(), LowPrice = list[5].ToDouble(), HighPrice = list[6].ToDouble(), TotalHand = list[7].ToInt(), TotalAmount = list[8].ToDouble(), HandRate = ((string)list[9]).Replace("%", "").ToDouble(), UpdateDate = DateTime.Now }; sd.ID = "{0}_{1}".F(sd.Code, sd.StatDate.ToString("yyyyMMdd")); #endregion res.Add(sd); } res.Save(true); } } #endregion }); }
static List <StockDayData> ParseText(string code, string text) { #region 单个文本解析 JsonParser jp = new JsonParser(text); var decode = (List <object>)jp.Decode(); if (decode.Count < 1) { return(new List <StockDayData>()); } var main = (Dictionary <string, object>)decode[0];//字典 if (main.ContainsKey("hq")) { var obj = (List <object>)main["hq"]; if (obj.Count > 0) { List <StockDayData> res = new List <StockDayData>(); foreach (var item in obj) { #region 单条记录解析 //item是一个10个元素的数组 //日期,今开价格,今天收盘价格,涨跌金额,涨跌幅度,最低价格,最高价格,总手,总金额(万),换手率 //"2018-02-09", "31.46", "31.46", "2.86", "10.00%", "31.46", "31.46", "303", "95.32", "0.15%" var list = (List <object>)item; StockDayData sd = new StockDayData() { Code = code, StatDate = list[0].ToDateTime(), StartPrice = list[1].ToDouble(), EndPrice = list[2].ToDouble(), ChangePrice = list[3].ToDouble(), ChangeRatio = ((string)list[4]).Replace("%", "").ToDouble(), LowPrice = list[5].ToDouble(), HighPrice = list[6].ToDouble(), TotalHand = list[7].ToInt(), TotalAmount = list[8].ToDouble(), HandRate = ((string)list[9]).Replace("%", "").ToDouble(), UpdateDate = DateTime.Now }; sd.ID = "{0}_{1}".F(sd.Code, sd.StatDate.ToString("yyyyMMdd")); #endregion res.Add(sd); } return(res); //res.Save(true); } } return(new List <StockDayData>()); #endregion }