Wednesday , June 29 2022

JSON Parsing in Android – Fetching From MySQL Database – Android Coding by DMTechnolab

// this method is actually fetching the json string

Private Zero getJSON()The last String urlWebService) {{

/ *

Fetching string as json is a network operation

* And we cannot do network operation in the main thread

* So we need an AsyncTask

* Here are the constraints defined

* Null -> we are not passing anything

* Nil -> nothing even on progress updates

* String -> After completion it should return a string and it will be the same string

* * /

class GetJSON Is spread AsyncTask<Zero, Zero, String> {{

// This method will be called before execution

// You can display a progress bar or something

// so that the user understands that he should wait

// As network operation may take some time


Protected Zero onPreExecute()) {{



// This method will be called after execution

// So here we are displaying a toast with jog string

@ Override

Protected Zero onPostExecute()String s) {{


Toast.Makeup()getApplicationContext()), s, Toast.LENGTH_SHORT).Display());


// In this method we are fetching the jugon string


Protected String doInBackground()Zero... voids) {{

try {{

// Creating a URL

URL url = = New URL()urlWebService);

// Opening URL using HttpURLConnection

HttpURLConnection With = = ()HttpURLConnection) url.Openness());

// StringBuilder to read string from object service

Stringburls Sb = = New Stringburls());

// We will use buffered reader to read string from service

Bufferreader Buffer = = New Bufferreader()New InputStreamReader()With.getInputStream())));

// a simple string to read values ​​from each row

String Jasan;

// we do not get reading until we read

whereas ()()Jasan = = Buffer.Line to read())) ! = Invalid) {{

// add it to string builder attach()Jasan + _ ”);


// return the string read at the end

The return Sb.Wire()).Trim());

} Hold ()exception I) {{

The return Invalid;




// Creating an asynctask object and executing it

GetJSON getJSON = = New GetJSON());



Source link

About dmtechnolab

Check Also

Simplified Coding

Android Hilt Tutorial – Injecting Dependencies with Hilt – Android Coding by DMTechnolab

You are welcome Android Hilt tutorial. I hope you all are aware of it Dependency …

Leave a Reply

Your email address will not be published. Required fields are marked *