2014-03-27 55 views
-4

请如何从此JSON获取 refresh_token如何从此JSON获取refresh_token(Java/Android)

{"scope":"https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/payments/futurepayments https://uri.paypal.com/services/invoicing openid https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/payments/.*","access_token":"fsdmpd19QszG4n-6mokPXS7uShe9qDO84kqQyR5kYVE","token_type":"Bearer","expires_in":900,"refresh_token":"WJAvbjuCzIOdgEsYUfywhxrygKQaCoaJo_F5pj7RMJERiovBmy1ua0Qhs81a_uLuiqjayJrqhycShf0TXHWKq7JbZZ4"} 
+0

可能重复:http://stackoverflow.com/questions/2591098/how-to-解析-JSON-中的Java – Gudgip

回答

2

试试这个..

try 
{ 
    JSONObject object = new JSONObject(response); 
    String refresh_token = object.getString("refresh_token"); 

}catch (JSONException e) { 
    e.printStackTrace(); 
} 
1

这是可以做到这样的:

public String getToken(String url) throws JSONException { 
    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    HttpGet httpGet = new HttpGet(url); 
    try { 
     HttpResponse response = httpclient.execute(httpGet); 
     JSONObject data = new JSONObject(EntityUtils.toString(response.getEntity())); 
     return data.getString("refresh_token"); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return null; 
}