【问题标题】:How to sort Data from WebClient Response如何对 WebClient 响应中的数据进行排序
【发布时间】:2014-07-20 15:22:10
【问题描述】:

我有一个这样的 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;

等等...谢谢。

【问题讨论】:

    标签: c# json windows-phone-8 webclient


    【解决方案1】:

    使用 Json 解析器。

    使用Json.Net

    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"];
    

    【讨论】:

      猜你喜欢
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2022-06-21
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      相关资源
      最近更新 更多