Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class main extends AppCompatActivity {
- String oName[] = new String [];
- int oAge [] = new int [];
- int oHand [] = new int [];
- protected void onCreate(Bundle savedInstanceState) {...}
- private class DownloadTask extends AsyncTask<String, Integer, String> {
- @Override
- protected String doInBackground (String... values) {
- InputStream is = null;
- String result = ""; //Get json?
- String line;
- try {
- URL ua = new URL("https://api.myjson.com/bins/r5kim"); //json address
- HttpURLConnection conn = (HttpURLConnection) ua.openConnection();
- conn.setRequestMethod("GET");
- conn.connect();
- is = conn.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- while ((line = reader.readLine()) != null) {
- result += line;
- }
- is.close();
- JSONObject jo = new JSONObject(result); //get json
- JSONArray op = jo.getJSONArray("opponents"); //json array?? parse??
- for(int i = 0; i < op.length(); i++) {
- oName[i] = op.getJSONObject(i).getString("name"); //Get null
- oAge[i] = op.getJSONObject(i).getInt("age"); //Get null
- oHand[i] = op.getJSONObject(i).getInt("hand"); //Get null
- }
- } catch (MalformedURLException e) { //exception
- e.printStackTrace();
- } catch (IOException e) { //exception
- e.printStackTrace();
- } catch (JSONException e) { //exception
- e.printStackTrace();
- }
- return null;
- }
Add Comment
Please, Sign In to add comment