- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想知道是否有一种方法可以操作 RestTemplate 类的方法 postForObject 返回的 JSON。我读到了一个关于类 JSONObject 的老问题,但我注意到它已被 JsonObject 取代,而且我不知道它是否以完全相同的方式工作。这是我的方法:
public void sendEmail() throws FirebaseAuthException {
Body body = new Body(firebase.createCustomToken("username"), true);
RestTemplate t = new RestTemplate();
Object response = t.postForObject(
"https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]",
body, Object.class);
}
firebase.createCustomToken("username")
method 是我用来为用户返回自定义 token 的方法。 firebase 对象是 FireBaseService
类的对象我在其中编写了使用 FireBase 的所有有用方法。我传递了一个 String 和一个 boolean 作为 POST 方法的主体。一切正常,但我不知道如何获取某个 JSON 字段的值。 response
的值是:
{
"idToken": "[ID_TOKEN]",
"refreshToken": "[REFRESH_TOKEN]",
"expiresIn": "3600"
}
我正在执行的 REST API 调用是这样的:https://firebase.google.com/docs/reference/rest/auth#section-verify-custom-token .
如何获取字段idToken
的值?
最佳答案
JSONObject json = (JSONObject) response;
String token = json.getString("refreshToken");
关于java - 操作从 postForObject 返回的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59246451/
我在 Spring rest 服务中有一个方法。 @RequestMapping(value = "test/process", method = RequestMethod.POST) public
我正在尝试使用 postforobject 检索对象,只有当我尝试检索自定义对象时,才会出现异常错误,如果我重写服务并返回单个字符串并将 postforobject 返回到一个字符串,它就可以正常工作
嗨,我希望客户端能够使用一个安静的网络服务。我使用 springboot,该服务返回一个仅包含一个对象的 JSON 列表。我想像这样使用 RestTemplate 的 postForObject Ap
给定一个类 EncoderService ,它具有以下 createNewStream 方法以及该方法中使用的一堆常量,我如何使用 mockito 来为 createNewStream 方法编写单元测
让客户端应该将纯 json 字符串发送到 RESTful 服务: ... final Gson gson = new GsonBuilder().create(); final
我必须使用 postForObject() 将 JSON 数据从一种服务方法发送到另一种服务方法方法。 我在 RestTemplate 上看到了一个例子在 this link . postForObj
我尝试模拟 Restful 服务器: private void btnPostActionPerformed(java.awt.event.ActionEvent evt) {
这个问题已经有答案了: How to parse JSON in Java (36 个回答) 已关闭 3 年前。 我想知道是否有一种方法可以操作 RestTemplate 类的方法 postForOb
我是 Mockito 以及 Spring 的 RestTemplate 的新手。我正在对一项功能进行 JUnit 测试,该功能向 Web 服务发送请求并通过使用 RestTemplate 获取响应。我
我正在尝试执行 RESTful Web 服务,但是,当我发送请求时,出现 HttpClientErrorException 消息“415 Unsupported Media Type”。 这是服务调用
我正在尝试向身份验证服务器发送帖子消息,并且我正在使用 postforobject。当我运行程序时,我收到“线程“main”中的异常 org.springframework.web.client.Ht
我试图使用 RestTemplate postForObject 使用 firebase Auth API,但是当我将 String.class 指定为其工作文件的返回类型时,但如果我指定自定义类来处
我正在尝试将消息列表发布到其余 api。如何为下面的 postJSONData 方法编写 mockito junit: public class PostDataService{ @Autow
我目前正在开发一个 Rest-Service,它需要调用同一服务器上提供的另一个 Rest-Method。因此,例如路径/myPath/foo 上的方法需要从路径/myPath/restApi/bar
使用返回 json 字符串的 restful api。格式是 { "status": "ok", "result": { } } 我正在尝试将用户配置文件的响应映射到 UserProfile
在使用 RestTemplate 发送 POST 请求时,我一直收到 400 BAD 请求。这是我的代码: MultiValueMap requestBody = new LinkedMult
我已经设置了包含字符串 ["a", "b", "c"] ,我想要 POST json 数据,例如(逗号分隔和一个字符串)这是 JSON {"view" : "a,b,c", "fruits" : "a
我目前有一个带有字符串字段的 RestTemplate 响应对象来获取响应数据。我想在同一个对象中发送 InputStream。 下面是响应类 @XmlRootElement public class
在 Spring Boot Junit 测试中,当调用 when(mockRestTemplate.postForObject(Mockito.any(), Mockito.any(),Mockito
我正在使用以下方法调用网络服务。 ResponseBean responseBean = getRestTemplate() .postForObject(url, customerBean,
我是一名优秀的程序员,十分优秀!