使用Java方法取出{access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiV0VCUyJdLCJ1c2VyX2lkIjoiMTY0MzgxNjExMTczMDU2MTAyNiIsInVzZXJfbmFtZSI6InF5dGVzdCIsInNjb3BlIjpbInJlYWQiXSwiZXhwIjoxNzE2MTA3NTU5LCJhdXRob3JpdGllcyI6WyJjdiJdLCJqdGkiOiJiZGE2MmY3OS1lMWM4LTQyYjEtODJlYi0zNWI1OGQ1YTA4OWEiLCJjbGllbnRfaWQiOiJ0ZXN0X2NsaWVudCJ9.19Vf7XxjwlroLWBFuQh0mqeLHnAbQti8Q0c9EveFPyo, token_type=bearer, refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiV0VCUyJdLCJ1c2VyX2lkIjoiMTY0MzgxNjExMTczMDU2MTAyNiIsInVzZXJfbmFtZSI6InF5dGVzdCIsInNjb3BlIjpbInJlYWQiXSwiYXRpIjoiYmRhNjJmNzktZTFjOC00MmIxLTgyZWItMzViNThkNWEwODlhIiwiZXhwIjoxNjg1MTExNTU5LCJhdXRob3JpdGllcyI6WyJjdiJdLCJqdGkiOiJmMGQ0NzdlYi05ZGI5LTQ1YTEtYjUyMy01YTljYjY0NzY2ZDUiLCJjbGllbnRfaWQiOiJ0ZXN0X2NsaWVudCJ9.VwOsvGGCb7SWGeIC_X8e7FQyjfbk5LXbgJMHj16ax1c, expires_in=31103999, scope=read, user_id=1643816111730561026, jti=bda62f79-e1c8-42b1-82eb-35b58d5a089a}中access_token
时间: 2024-02-05 17:12:50 浏览: 154
可以使用如下的Java方法来取出access_token:
```
public String getAccessToken(String tokenString) {
String accessToken = "";
if (tokenString != null && !tokenString.isEmpty()) {
String[] tokens = tokenString.split(",");
for (String token : tokens) {
if (token.contains("access_token=")) {
accessToken = token.split("=")[1];
break;
}
}
}
return accessToken;
}
```
调用方法如下:
```
String tokenString = "{access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiV0VCUyJdLCJ1c2VyX2lkIjoiMTY0MzgxNjExMTczMDU2MTAyNiIsInVzZXJfbmFtZSI6InF5dGVzdCIsInNjb3BlIjpbInJlYWQiXSwiZXhwIjoxNzE2MTA3NTU5LCJhdXRob3JpdGllcyI6WyJjdiJdLCJqdGkiOiJiZGE2MmY3OS1lMWM4LTQyYjEtODJlYi0zNWI1OGQ1YTA4OWEiLCJjbGllbnRfaWQiOiJ0ZXN0X2NsaWVudCJ9.19Vf7XxjwlroLWBFuQh0mqeLHnAbQti8Q0c9EveFPyo, token_type=bearer, refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiV0VCUyJdLCJ1c2VyX2lkIjoiMTY0MzgxNjExMTczMDU2MTAyNiIsInVzZXJfbmFtZSI6InF5dGVzdCIsInNjb3BlIjpbInJlYWQiXSwiYXRpIjoiYmRhNjJmNzktZTFjOC00MmIxLTgyZWItMzViNThkNWEwODlhIiwiZXhwIjoxNjg1MTExNTU5LCJhdXRob3JpdGllcyI6WyJjdiJdLCJqdGkiOiJmMGQ0NzdlYi05ZGI5LTQ1YTEtYjUyMy01YTljYjY0NzY2ZDUiLCJjbGllbnRfaWQiOiJ0ZXN0X2NsaWVudCJ9.VwOsvGGCb7SWGeIC_X8e7FQyjfbk5LXbgJMHj16ax1c, expires_in=31103999, scope=read, user_id=1643816111730561026, jti=bda62f79-e1c8-42b1-82eb-35b58d5a089a}";
String accessToken = getAccessToken(tokenString);
System.out.println(accessToken);
```
这个方法会输出:
```
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiV0VCUyJdLCJ1c2VyX2lkIjoiMTY0MzgxNjExMTczMDU2MTAyNiIsInVzZXJfbmFtZSI6InF5dGVzdCIsInNjb3BlIjpbInJlYWQiXSwiZXhwIjoxNzE2MTA3NTU5LCJhdXRob3JpdGllcyI6WyJjdiJdLCJqdGkiOiJiZGE2MmY3OS1lMWM4LTQyYjEtODJlYi0zNWI1OGQ1YTA4OWEiLCJjbGllbnRfaWQiOiJ0ZXN0X2NsaWVudCJ9.19Vf7XxjwlroLWBFuQh0mqeLHnAbQti8Q0c9EveFPyo
```
阅读全文