gpt4 book ai didi

c# - 如何使用 Web 客户端解析 json 并将其显示在控制台中?

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:06 24 4
gpt4 key购买 nike

WebClient client = new WebClient();

string value = client.DownloadString("http://www.onemap.sg/publictransportation/service1.svc/routesolns?token=qo/s2TnSUmfLz+32CvLC4RMVkzEFYjxqyti1KhByvEacEdMWBpCuSSQ+IFRT84QjGPBCuz/cBom8PfSm3GjEsGc8PkdEEOEr&sl=39167.4524,35518.8625&el=28987.5163,33530.5653&startstop=&endstop=&walkdist=300&mode=bus&routeopt=cheapest&retgeo=true&maxsolns=1&callback=");

// Write values.
Console.WriteLine("Results:");
Console.WriteLine(value.Length);
Console.WriteLine(value);

错误信息显示:'System.Net.WebClient' 不包含 'DownloadString' 的定义,并且找不到接受类型为 'System.Net.WebClient' 的第一个参数的扩展方法 'DownloadString'(您是否缺少 using 指令或程序集引用?)

最佳答案

在 Windows Phone 中,大多数情况下您不得不以异步方式进行编程。因此,您必须使用 DownloadStringAsync 而不是 DownloadString,如本示例中所示:

  var client = new WebClient();

client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(loadHTMLCallback);
client.DownloadStringAsync(new Uri("http://www.myurl.com/myFile.txt"));
//...

public void loadHTMLCallback(Object sender, DownloadStringCompletedEventArgs e)
{
var textData = (string)e.Result;
// Do cool stuff with result
Debug.WriteLine(textData);
}

来源: http://developer.nokia.com/community/wiki/Asynchronous_Programming_For_Windows_Phone_8

关于c# - 如何使用 Web 客户端解析 json 并将其显示在控制台中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22394488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com