|
发表于 2019-8-8 20:41:05
|
显示全部楼层
江苏省南京市
本帖最后由 曜石头 于 2019-8-9 07:24 编辑
1、尝试编写一个Cookie简化函数,将Cookie 中的 path domain express max-age 等无用信息清除
public static string SimplifyCookie(IEnumerable<string> SCookie) {
if (SCookie == null) return null;
string sc = string.Join("", SCookie);
string[] strarr = sc.Split(';');
string str;
List<string> list = new List<string>();
foreach (var item in strarr){
str = item.Substring(0,item.IndexOf("="));
if (str!= " path" && str != " domain"&& str != " expires" && str != " max-age") {
list.Add(item);
}
}
string str2 = string.Join(";", list);
return str2;
}
2、第38天口头作业:360搜索联想SearchAssociateof360
private async void TextInput_TextChanged(object sender, EventArgs e){
ListAssociate.Visible = false;
HttpClient HttpClient = new HttpClient();
string str = await HttpClient.GetStringAsync($"https://sug.so.360.cn/suggest?callback=suggest_so&encodein=utf-8&encodeout=utf-8&format=json&fields=word&word={TextInput.Text}");
if (!string.IsNullOrWhiteSpace(str)) {
Match Match = Regex.Match(str, @"suggest_so\((.*?)\);");
if (Match.Success) {
str = Match.Groups[1].Value;
Root Root = JsonConvert.DeserializeObject<Root>(str);
if (Root.result != null && Root.result.Count > 0){
ListAssociate.Visible = true;
ListAssociate.DataSource = Root.result; //这里会调用Result类的ToString方法
}
}
}
}
public class Result{
public override string ToString(){
return this.word;
}
}
public class Root{
public List<Result> result { get; set; }
}
解析jison还要自己定义对象好麻烦啊 |
|