如何从WebClient响应中排序数据

本文关键字:排序 数据 响应 WebClient | 更新日期: 2023-09-27 18:13:49

我有一个这样的WebClient:

private void Button_Click(object sender, RoutedEventArgs e)
{
    WebClient wc = new WebClient();
    wc.DownloadStringAsync(new Uri(myurl));
    wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
}

处理程序:

private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    MessageBox.Show(e.Result.ToString());
}

这就是我得到的:

    {"out_error":"",
"out_id":4274,
"out_device_hash":"7a8e4f7a264a6afb38cfadb6b50e7a45c58d226b",
"out_device_name":"Unnamed device",
"out_uname":"User Name",
"token":"e1c063d16fee7bb8912099034f67c2d17a8f45c3"}

问题是我如何让这些字符串排序到单独的字符串,就像在xml:

string error = out_error;
string id = out_id;

等等…谢谢。

如何从WebClient响应中排序数据

使用Json解析器

使用Json。净

var dict1 = JsonConvert.DeserializeObject<Dictionary<string, string>>(e.Result);
使用JavaScriptSerializer

var dict2 = new JavaScriptSerializer()
            .Deserialize<Dictionary<string, string>>(e.Result);

string id = dict1["out_id"];