【发布时间】:2017-09-24 10:58:45
【问题描述】:
我有一个来自 PHP 的这样的 json 列表:
$Json = '[{"test":"1", "message":"try it"},
{"test":"2", "message":"try it"}, {"test":"3", "message":"try it"} ...]';
$final = [ 'error' => '1', 'json' => json_encode($Json)];
die(json_encode($final));
在 Android 中,我可以显示如下结果:
JsonParser jsonParser = new JsonParser();
JsonObject res = (JsonObject) jsonParser.parse(new Gson().toJson(response.body()));
Log.w("Return", response.body().toString());
到目前为止一切正常,但是当我尝试从返回的结果中创建一个新的 Json Object 时,我收到以下错误消息:
com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonObject
我做了什么:
JsonObject json = (JsonObject) jsonParser.parse(new Gson().toJson(res.get("json").toString()));
Log.w("JSON", json.toString());
请问有什么办法吗?
【问题讨论】: