public static void ExtractWeiboData(string filename) { JArray jaInput = new JArray(); jaInput = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"../../input/" + filename)); foreach (JObject jo in jaInput) { if (jo["deleted"] == null) { WeiboData weiboTemp = new WeiboData(); //微博信息 weiboTemp.Id = jo["id"].ToString(); weiboTemp.CreatedAt = jo["created_at"].ToString(); weiboTemp.Text = jo["text"].ToString(); if (jo["pic_ids"].ToArray().Count() != 0) { //weiboTemp.PicIds = jo["pic_ids"].ToString(); weiboTemp.PicCount = jo["pic_ids"].ToArray().Count().ToString(); } else { //weiboTemp.PicIds = "null"; weiboTemp.PicCount = "0"; } if (jo["geo"].Children().Count() != 0) { weiboTemp.Lat = jo["geo"]["coordinates"].ToArray()[0].ToString(); weiboTemp.Lng = jo["geo"]["coordinates"].ToArray()[1].ToString(); } else { weiboTemp.Lat = "null"; weiboTemp.Lng = "null"; } //微博用户信息 weiboTemp.UserId = jo["user"]["id"].ToString(); weiboTemp.UserProvince = jo["user"]["province"].ToString(); weiboTemp.UserCity = jo["user"]["city"].ToString(); //微博签到信息 if (jo["annotations"] != null) { weiboTemp.AnnotationsId = jo["annotations"].ToArray()[0]["place"]["poiid"].ToString(); weiboTemp.AnnotationsTitle = jo["annotations"].ToArray()[0]["place"]["title"] != null ? jo["annotations"].ToArray()[0]["place"]["title"].ToString():"null"; if (jo["annotations"].ToArray()[0]["place"]["lat"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["lat"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["lon"].ToString(); } else if (jo["annotations"].ToArray()[0]["place"]["latitude"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["latitude"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["longitude"].ToString(); } else { weiboTemp.AnnotationsLat = "null"; weiboTemp.AnnotationsLng = "null"; } } listHasData.Add(weiboTemp); Console.WriteLine("listHasData:" + listHasData.Count); } else { WeiboData weiboTemp = new WeiboData(); //微博信息 weiboTemp.Id = jo["id"].ToString(); weiboTemp.CreatedAt = jo["created_at"].ToString(); //微博签到信息 if (jo["annotations"] != null) { weiboTemp.AnnotationsId = jo["annotations"].ToArray()[0]["place"]["poiid"].ToString(); weiboTemp.AnnotationsTitle = jo["annotations"].ToArray()[0]["place"]["title"] != null ? jo["annotations"].ToArray()[0]["place"]["title"].ToString() : "null"; if (jo["annotations"].ToArray()[0]["place"]["lat"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["lat"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["lon"].ToString(); } else if (jo["annotations"].ToArray()[0]["place"]["latitude"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["latitude"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["longitude"].ToString(); } else { weiboTemp.AnnotationsLat = "null"; weiboTemp.AnnotationsLng = "null"; } } listNullData.Add(weiboTemp); Console.WriteLine("listNullData:" + listNullData.Count); jaInput = null; } } }
public static void ExtractWeiboData(string filename) { JArray jaInput = new JArray(); jaInput = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"../../input/" + filename)); foreach (JObject jo in jaInput) { if (jo["deleted"] == null) { WeiboData weiboTemp = new WeiboData(); //微博信息 weiboTemp.Id = jo["id"].ToString(); weiboTemp.CreatedAt = jo["created_at"].ToString(); weiboTemp.Text = jo["text"].ToString(); if(jo["pic_ids"].ToArray().Count() != 0 ){ //weiboTemp.PicIds = jo["pic_ids"].ToString(); weiboTemp.PicCount = jo["pic_ids"].ToArray().Count().ToString(); } else { //weiboTemp.PicIds = "null"; weiboTemp.PicCount = "0"; } if (jo["geo"].Children().Count() != 0) { weiboTemp.Lat = jo["geo"]["coordinates"].ToArray()[0].ToString(); weiboTemp.Lng = jo["geo"]["coordinates"].ToArray()[1].ToString(); } else { weiboTemp.Lat = "null"; weiboTemp.Lng = "null"; } //微博用户信息 weiboTemp.UserId = jo["user"]["id"].ToString(); weiboTemp.UserProvince = jo["user"]["province"].ToString(); weiboTemp.UserCity = jo["user"]["city"].ToString(); //微博签到信息 if (jo["annotations"] != null) { weiboTemp.AnnotationsId = jo["annotations"].ToArray()[0]["place"]["poiid"].ToString(); weiboTemp.AnnotationsTitle = jo["annotations"].ToArray()[0]["place"]["title"] != null ? jo["annotations"].ToArray()[0]["place"]["title"].ToString():"null"; if (jo["annotations"].ToArray()[0]["place"]["lat"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["lat"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["lon"].ToString(); } else if (jo["annotations"].ToArray()[0]["place"]["latitude"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["latitude"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["longitude"].ToString(); } else { weiboTemp.AnnotationsLat = "null"; weiboTemp.AnnotationsLng = "null"; } } listHasData.Add(weiboTemp); Console.WriteLine("listHasData:" + listHasData.Count); } else { WeiboData weiboTemp = new WeiboData(); //微博信息 weiboTemp.Id = jo["id"].ToString(); weiboTemp.CreatedAt = jo["created_at"].ToString(); //微博签到信息 if (jo["annotations"] != null) { weiboTemp.AnnotationsId = jo["annotations"].ToArray()[0]["place"]["poiid"].ToString(); weiboTemp.AnnotationsTitle = jo["annotations"].ToArray()[0]["place"]["title"] != null ? jo["annotations"].ToArray()[0]["place"]["title"].ToString() : "null"; if (jo["annotations"].ToArray()[0]["place"]["lat"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["lat"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["lon"].ToString(); } else if (jo["annotations"].ToArray()[0]["place"]["latitude"] != null) { weiboTemp.AnnotationsLat = jo["annotations"].ToArray()[0]["place"]["latitude"].ToString(); weiboTemp.AnnotationsLng = jo["annotations"].ToArray()[0]["place"]["longitude"].ToString(); } else { weiboTemp.AnnotationsLat = "null"; weiboTemp.AnnotationsLng = "null"; } } listNullData.Add(weiboTemp); Console.WriteLine("listNullData:" + listNullData.Count); jaInput = null; } } }