private static List <KeyValue> GetItemKeyValue(HashObject hash, Key key) { object data; if (!hash.TryGetValue(key.Name, out data)) { return(null); } if (key.Children.Count == 0) { KeyValue kv = new KeyValue(); kv.Add(key.Name, data); return(new List <KeyValue>() { kv }); } List <KeyValue> list = GetListHashValue(key, data); return(list ?? GetChildrenKeyValue(key, data)); }
public object GetTaobaoRealPrice(string url, string refer, List <SkuMap> skuMaps) { string html = GetHtml(url, refer).ToString().Trim(); string flag = "onSibRequestSuccess("; string data = html.Substring(flag.Length).TrimEnd(';').TrimEnd(')'); if (!data.Contains("promoData")) { return(skuMaps); } JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance(); HashObject hash = serializer.Deserialize <HashObject>(data); string[] keys = { "data/deliveryFee/data/sendCity", "data/tradeContract/pay", "data/tradeContract/service", "data/couponActivity/coupon/couponList", "data/promotion/promoData", "data/dynStock/sku", "data/promotion/soldQuantity/soldTotalCount", "data/promotion/soldQuantity/confirmGoodsCount" }; var temp = hash.GetHashValue(keys); Goods goods = new Goods(); goods.SendCity = temp.GetDataEx <string>("sendCity"); goods.Pays = GetGoodsPayWay(temp.GetDataEx <ArrayList>("pay")); goods.Service = GetGoodsService(temp.GetDataEx <ArrayList>("service")); goods.Skus = skuMaps; goods.Coupon = GetGoodsCoupon(temp.GetDataEx <ArrayList>("couponList")); goods.SoldTotalCount = temp.GetDataEx <decimal>("soldTotalCount"); goods.ConfirmGoodsCount = temp.GetDataEx <decimal>("confirmGoodsCount"); HashObject promoDatas = temp.GetDataEx <HashObject>("promoData"); if (promoDatas != null) { foreach (SkuMap map in skuMaps) { object keySku; if (promoDatas.TryGetValue(map.Key, out keySku)) { ArrayList list = (ArrayList)keySku; decimal minPrice = map.PromotionPrice; foreach (HashObject tempList in list) { minPrice = Math.Min(minPrice, tempList.GetValue <decimal>("price")); } map.PromotionPrice = minPrice; } } } HashObject sku = temp.GetDataEx <HashObject>("sku"); if (sku != null) { foreach (SkuMap map in skuMaps) { object keySku; if (sku.TryGetValue(map.Key, out keySku)) { map.Stock = ((HashObject)keySku).GetValue <decimal>("sellableQuantity"); } } } return(goods); }