Monday 4 April 2016

C# retrieve JSON from URL



I am creating a program that gets the steam market prices for various CS:GO items, and compares them to one another. I am having trouble getting the steam market JSON into my program. Market JSON
Here is my code:



using (WebClient webClient = new System.Net.WebClient())

{
WebClient n = new WebClient(); // <-- error on this line
string json = n.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New");
dynamic array = JsonConvert.DeserializeObject(json);
test.Text = array.lowest_price.ToString(); ;
}


I am getting this error when instanciating WebClient():





An unhandled exception of type 'System.Net.WebException' occurred in
System.dll



Additional information: The remote server returned an error: (500)
Internal Server Error.




Is this even a valid JSON? If not, is there an alternative? I heard backpack.tf has an api as well. Would this be better?
Thanks



Answer



Looks like the URL is malformed. I.just tried http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow%20Case and it returned a good response.



Of particular note is the enclosed parenthesis in your URL.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...