Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Metoda(View v) throws IOException, JSONException
- {
- TextView tv = (TextView) findViewById(R.id.wyswietl);
- JSONObject jsonObject = readJSONFromURL("http://api.fixer.io/latest?base=USD");
- String s = jsonObject.get("rates").toString();
- tv.setText(s);
- }
- static JSONObject readJSONFromURL(String url) throws IOException, JSONException
- {
- InputStream inputStream = new URL(url).openStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
- String jsonText = readAllFromJSON(bufferedReader);
- return new JSONObject(jsonText);
- }
- private static String readAllFromJSON(BufferedReader bufferedReader) throws IOException
- {
- StringBuilder stringBuilder = new StringBuilder();
- int i;
- while((i = bufferedReader.read()) != -1)
- {
- stringBuilder.append((char) i);
- }
- return stringBuilder.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment