Advertisement
nurnobishanto73

Jsonn Load

Jan 22nd, 2021
1,254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. getJSON("http://app.nurnobishanto.com/livetvadmin/custom-api.php?slider",1);
  2.  getJSON("http://app.nurnobishanto.com/livetvadmin/custom-api.php?features",2);
  3.        getJSON("http://app.nurnobishanto.com/livetvadmin/custom-api.php?info",3);
  4.      
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. private void getJSON(final String urlWebService, int b) {
  12.  
  13.         class GetJSON extends AsyncTask<Void, Void, String> {
  14.  
  15.             @Override
  16.             protected void onPreExecute() {
  17.                 super.onPreExecute();
  18.             }
  19.  
  20.  
  21.             @Override
  22.             protected void onPostExecute(String s) {
  23.                 super.onPostExecute(s);
  24.                 //  Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
  25.                 try {
  26.  
  27.                     if(b==1){
  28.                         loadIntoListView(s);
  29.  
  30.                     }else if(b==2) {
  31.  
  32.                         loadIntoListView2(s);
  33.                     }else if(b==3){
  34.                         loadInfo(s);
  35.                     }
  36.  
  37.  
  38.  
  39.                 } catch (JSONException e) {
  40.                     e.printStackTrace();
  41.                 }
  42.             }
  43.  
  44.             @Override
  45.             protected String doInBackground(Void... voids) {
  46.                 try {
  47.                     URL url = new URL(urlWebService);
  48.                     HttpURLConnection con = (HttpURLConnection) url.openConnection();
  49.                     StringBuilder sb = new StringBuilder();
  50.                     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
  51.                     String json;
  52.                     while ((json = bufferedReader.readLine()) != null) {
  53.                         sb.append(json + "\n");
  54.                     }
  55.                     return sb.toString().trim();
  56.                 } catch (Exception e) {
  57.                     return null;
  58.                 }
  59.             }
  60.         }
  61.         GetJSON getJSON = new GetJSON();
  62.         getJSON.execute();
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement