如何从URL的JSON字符串? [英] How to get a json string from url?
问题描述
我交换我的code形式的XML JSON。
I'm switching my code form XML to JSON.
但我找不到如何从一个给定的URL的JSON字符串。
But I can't find how to get a JSON string from a given url.
该URL是这样的:<一个href=\"https://api.facebook.com/method/fql.query?query=.....&format=json\">https://api.facebook.com/method/fql.query?query=.....&format=json\"
The URL is something like this: "https://api.facebook.com/method/fql.query?query=.....&format=json"
我以前用过XDocuments,有我可以使用加载方法:
I used XDocuments before, there I could use the load method:
XDocument doc = XDocument.load("URL");
这是什么方法JSON的相同呢?我使用JSON.NET。
What is the equivalent of this method for JSON? I'm using JSON.NET.
推荐答案
使用 Web客户端
类 System.Net
:
var json = new WebClient().DownloadString("url");
记
请即 Web客户端
是的IDisposable
,所以你可能会添加使用
语句来此生产code。这将是这样的:
Keep in mind that WebClient
is IDisposable
, so you would probably add a using
statement to this in production code. This would look like:
using (WebClient wc = new WebClient())
{
var json = wc.DownloadString("url");
}
这篇关于如何从URL的JSON字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!