如何从这个JSON(Java / Android)中获取refresh_token

时间:2014-03-27 12:07:31

标签: java android json

请问我该如何获得 refresh_token 超出此JSON ??

{"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"}

2 个答案:

答案 0 :(得分:2)

试试这个..

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

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

答案 1 :(得分: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;
}