gpt4 book ai didi

java - Android 新手 - 无法从服务器响应中提取 token

转载 作者:行者123 更新时间:2023-12-02 02:43:42 25 4
gpt4 key购买 nike

我运行这段代码:

        protected Object doInBackground(Object[] objects) {
HttpClient client = new HttpClient();
client.get(get_token, new HttpResponseCallback() {
@Override
public void success(String responseBody) {

runOnUiThread(new Runnable() {
@Override
public void run() {

llHolder.setVisibility(View.VISIBLE);
}
});
token = responseBody;

}

responseBody 给了我回复:

{"response":{"token":"eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmlJ9","status":"success"}}

如何获取字符串形式的“token”,与“status”相同

最佳答案

使用此代码。

   protected Object doInBackground(Object[] objects) {
HttpClient client = new HttpClient();
client.get(get_token, new HttpResponseCallback() {
@Override
public void success(String responseBody) {

runOnUiThread(new Runnable() {
@Override
public void run() {

llHolder.setVisibility(View.VISIBLE);

try {
JSONObject jObject = new JSONObject(responseBody);
String token = jObject.getString("token");

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

}
});
}

更多信息请查看this answer

关于java - Android 新手 - 无法从服务器响应中提取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45001982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com