0
这是我收到的JSON:的Json反序列化 - 预期BEGIN_OBJECT但STRING
{
"data": "{\"keystring\": \"ag5zfmNvcGFya3NlcnZlcnIUCxIHQ29tbWVudBiAgICAusaBCgw\"}",
"isSucceed": true,
"error": ""
}
这是类和这是应该的代码反序列化它:
public class ServerResponse {
private boolean isSucceed;
private String error;
private JSONObject data;
}
//this is the code line responsible for deserialization, responseJson = the JSON above
ServerResponse response = gson.fromJson(responseJson, ServerResponse.class);
对于某些原因我得到JsonSyntaxException:预期的BEGIN_OBJECT,但是STRING,我猜是与数据对象ServerResponse举行,但我收到它作为一个有效的JSON ...
任何想法?
我该如何编写我自己的TypeAdapter? – Jjang 2014-10-01 16:11:46
@Jjang这是一个Gson类。 [这里是一个例子。](http://www.javacreed.com/gson-typeadapter-example/) – 2014-10-01 16:14:06
TypeAdapter绝对是这种方式。 – dharms 2014-10-01 16:25:17