2017-04-03 59 views
0

我有這個網址:https://euw.api.riotgames.com/api/lol/EUW/v1.4/summoner/by-name/motschel123?api_key=RGAPI-6A9B210B-31F9-4AD9-8393-1CF3DA6E10EF使用API​​(RITO API)與Java(Android版)

而且我想在網站上的數據:

try { 
    URL url = new URL("https://euw.api.riotgames.com/api/lol/" + region + "/v1.4/summoner/by-name/" + summonerN + "?api_key=" + apiCode); 
    parseJSON(url); 
} catch (MalformedURLException e) { 
    Toast.makeText(getBaseContext(), "Error creating URL", 
        Toast.LENGTH_LONG).show(); 
} catch (Exception e) { 
    Toast.makeText(getBaseContext(), "Error reading URL", 
        Toast.LENGTH_LONG).show(); 
} 

而且功能parseJSON(URL url)

public void parseJSON(URL url) throws Exception{ 
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); 

    String inputLine; 
    while ((inputLine = in.readLine()) != null) 
     Toast.makeText(getBaseContext(), inputLine, 
         Toast.LENGTH_LONG).show(); 
    in.close(); 
} 

但它不起作用,只是拋出一個Exception。 我該如何解決它?

+0

使用retrofi庫創建的getter setter方法,這將是很容易以檢索從動態數據url –

+0

@Akashkumar retrofiT? – motschel123

+0

找到下面的答案。我提供 –

回答