C# 如何对WebClient响应中的数据进行排序
我有这样一个网络客户端:C# 如何对WebClient响应中的数据进行排序,c#,json,windows-phone-8,webclient,C#,Json,Windows Phone 8,Webclient,我有这样一个网络客户端: private void Button_Click(object sender, RoutedEventArgs e) { WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri(myurl)); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringComp
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;
等等。。。谢谢。使用Json解析器
使用
var dict1=JsonConvert.DeserializeObject(e.Result);
使用
var dict2=新的JavaScriptSerializer()
.反序列化(如结果);
字符串id=dict1[“out_id”];
var dict1 = JsonConvert.DeserializeObject<Dictionary<string, string>>(e.Result);
var dict2 = new JavaScriptSerializer()
.Deserialize<Dictionary<string, string>>(e.Result);
string id = dict1["out_id"];