【问题标题】:How do I get the refresh_token out of this JSON (Java/Android) [closed]如何从此 JSON(Java/Android)中获取 refresh_token [关闭]
【发布时间】:2014-03-27 12:07:31
【问题描述】:

请问如何获得 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"}

【问题讨论】:

标签: java android json


【解决方案1】:

试试这个..

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

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

【讨论】:

    【解决方案2】:

    可以这样做:

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多