Guest User

Untitled

a guest
Jun 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. public class main extends AppCompatActivity {
  2. String oName[] = new String [];
  3. int oAge [] = new int [];
  4. int oHand [] = new int [];
  5.  
  6. protected void onCreate(Bundle savedInstanceState) {...}
  7.  
  8. private class DownloadTask extends AsyncTask<String, Integer, String> {
  9. @Override
  10. protected String doInBackground (String... values) {
  11. InputStream is = null;
  12. String result = ""; //Get json?
  13. String line;
  14. try {
  15. URL ua = new URL("https://api.myjson.com/bins/r5kim"); //json address
  16. HttpURLConnection conn = (HttpURLConnection) ua.openConnection();
  17. conn.setRequestMethod("GET");
  18. conn.connect();
  19. is = conn.getInputStream();
  20. BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  21. while ((line = reader.readLine()) != null) {
  22. result += line;
  23. }
  24. is.close();
  25. JSONObject jo = new JSONObject(result); //get json
  26. JSONArray op = jo.getJSONArray("opponents"); //json array?? parse??
  27. for(int i = 0; i < op.length(); i++) {
  28. oName[i] = op.getJSONObject(i).getString("name"); //Get null
  29. oAge[i] = op.getJSONObject(i).getInt("age"); //Get null
  30. oHand[i] = op.getJSONObject(i).getInt("hand"); //Get null
  31. }
  32. } catch (MalformedURLException e) { //exception
  33. e.printStackTrace();
  34. } catch (IOException e) { //exception
  35. e.printStackTrace();
  36. } catch (JSONException e) { //exception
  37. e.printStackTrace();
  38. }
  39. return null;
  40. }
Add Comment
Please, Sign In to add comment