0

I am trying to make for example a simple weather app. Mine is for an Air Quality API.

I had this code but I didn't think it would work with JSON.

var webClient = new WebClient();
...
var text = e.Result; // get the downloaded text and store in this variable
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "downloaded.txt"; // local file to save text in
string localPath = Path.Combine(documentsPath, localFilename); // local path to save file to
File.WriteAllText(localPath, text); // writes to local storage
myTextView.Text = text; // updates the TextView element on the screen with downloaded text data

Then Just

var url = new Uri("https://api.breezometer.com/baqi/?lat=" + latitude + "&lon=" + longitude +"&key=YOUR KEY HERE");
webClient.Encoding = Encoding.UTF8;
webClient.DownloadStringAsync(url);  

Im just not sure of the encoding method for JSON. If anyone knows please answer thanks...

jzeferino
  • 7,700
  • 1
  • 39
  • 59

1 Answers1

0

Use the WebClient class in System.Net:

var json = new WebClient().DownloadString("url");

Origin answer: How to get a json string from url?

Community
  • 1
  • 1
Raskayu
  • 735
  • 7
  • 20
  • I can post the system log but [link](https://drive.google.com/file/d/0B66vfwSXdArkRzVRTWZqTnVSTHc/view?usp=sharing) @Raskayu – Lachlan Jones Aug 04 '16 at 04:02
  • Try like this: `var url = new Uri(url link); using (WebClient wc = new WebClient()) { var json = wc.DownloadString(url); }` and for parse the json string result to get an actual object see [this](http://stackoverflow.com/questions/2859753/what-is-the-simplest-c-sharp-function-to-parse-a-json-string-into-an-object) @LachlanJones PD: I've tried the solution and I can get a correct json string answer, just saying that my location was wrong :P – Raskayu Aug 04 '16 at 06:24