无法使用Gson库读取json响应

时间:2016-07-26 01:38:10

标签: java json gson

我不确定我在这里缺少什么。所有我试图读取响应并返回布尔值。我得到的错误是java.lang.RuntimeException: Unable to invoke no-args constructor for interface javax.json.JsonValue. Register an InstanceCreator with Gson for this type may fix this problem.

response = {StringBuffer@5339} "{  "success": true,  "challenge_ts": "2016-07-26T14:52:29Z",  "hostname": "localhost"}"

response.toString = "{  "success": true,  "challenge_ts": "2016-07-26T14:52:29Z",  "hostname": "localhost"}"

Gson gson = new Gson();

JsonObjectjsonObject = gson.fromJson(response.toString(),String.class); //response type is StringBuffer.

return jsonObject.getBoolean("success");

感谢您的帮助。

0 个答案:

没有答案