public JObject WxInit() { string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"\",\"DeviceID\":\"e1615250492\"}}}}"; Cookie sid = BaseService.GetCookie("wxsid"); Cookie uin = BaseService.GetCookie("wxuin"); if (sid != null && uin != null) { init_json = string.Format(init_json, uin.Value, sid.Value); byte[] bytes = BaseService.SendPostRequest(_init_url + "&pass_ticket=" + LoginService.Pass_Ticket, init_json); string init_str = Encoding.UTF8.GetString(bytes); JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject; foreach (JObject synckey in init_result["SyncKey"]["List"]) //同步键值 { _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString()); //已添加了具有相同键的项 求帮忙下,我是在winform想实现 } return init_result; } else { return null; } } /// <summary> /// 获取好友头像 /// </summary> /// <param name="username"></param> /// <returns></returns> public Image GetIcon(string username) { byte[] bytes = BaseService.SendGetRequest(_geticon_url + username); return Image.FromStream(new MemoryStream(bytes)); } /// <summary> /// 获取微信讨论组头像 /// </summary> /// <param name="usename"></param> /// <returns></returns> public Image GetHeadImg(string usename) { byte[] bytes = BaseService.SendGetRequest(_getheadimg_url + usename); return Image.FromStream(new MemoryStream(bytes)); }
_syncKey是字典对象吗?
_syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString());
改成
_syncKey[synckey["Key"].ToString()] = synckey["Val"].ToString();
这样改动的话,后面获取到的信息会覆盖掉之前的信息