android - Download a JSON string from a website with AsyncTask -


I have an Android application and I want to download a JSON file from a website using AsyncTask.

So far I have

  Public category downloader task asink & lt; String, zero, string [] & gt; {Private MyActivity myactivity; Personal reference references; Private string rawfid [] = new string [3]; Downloader Task (Myactivity Maternity) {myactivity = parent; Context = parent.getApplicationContext (); } @ Override protected string [] doInBackground (string ... parameter) {boolean full = false; InputStream input = null; OutputStream Output = Null; HttpURL Connection Connection = Faucet; For (int i = 0; i & lt; params.lamp; i ++) {try {url = url} new URL (perm [i]); Connection = (HttpURL connection) url.openConnection (); Connection.connect (); Input = connection.getInputStream (); } Hold (exception e) {}} return raw; } @ Override Protected Zero at PreExecute () {super.onPreExecute (); } @ Override Protected Zero at PostXextrack (string [] strings) {if (maturity! = Empty) {myactivity.setRefreshed (strings); }}  

I'm not sure how to walk from here

The website I am downloading is:

And when This is just a page on the site, on which there is a bunch of text, a JSON file.

The given parameter in AsyncCass is an array of 3 strings, each string that contains the URL in which I need to download

I use it to read all the contents of an input stream:

  string inputstreamtoastring (inputstream) {buffed reader reader = new buffed reader ( New InputStream Reader (is)); Stringbuilder stringbillder = new stringbilder (); String line = null; Try {while ((line = reader.readLine ()) = null {stringBuilder.append (line); }         is close(); } Grip (IOException E) {} Return StringBuilder. Toting (); }  

Then, to parse it as a JSON, you can create Java JSONObject with that string.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -