我正在尝试转换这个基于 64 的编码 JSON 字符串,并使用 flexjson API 将接收到的 JSON 转换为 POJO。
第一个尝试块,将直接 JSON 作为字符串转换为成功的对象。该字符串是使用在线工具解码的。
现在第二个尝试块,尝试以类似的方式将基于 64 的字符串转换为对象,但在运行时转换基于 64 的字符串,这会抛出异常flexjson.JSONException: Expected a ',' or ']' at character 10
try {
AsyncResponseDO asyncResponseDO = new JSONDeserializer<AsyncResponseDO>().deserialize("{\"relatesTo\":\"7_Sept2017_IF01\"}", AsyncResponseDO.class);
System.out.println(asyncResponseDO.getRelatesTo());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
AsyncResponseDO asyncResponseDO = new JSONDeserializer<AsyncResponseDO>().deserialize(Base64.decodeBase64("eyJyZWxhdGVzVG8iOiI3X1NlcHQyMDE3X0lGMDEifQ==".getBytes()).toString(), AsyncResponseDO.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
POJO类:
public class AsyncResponseDO {
private String relatesTo;
public String getRelatesTo() {
return relatesTo;
}
public void setRelatesTo(String relatesTo) {
this.relatesTo = relatesTo;
}
}