我正在尝试转换这个基于64位的编码JSON字符串,并使用flexjson API将收到的JSON转换为POJO。
首先尝试阻止,将直接JSON转换为字符串转换为成功的对象。该字符串使用在线工具解码。
现在第二次尝试阻止,尝试以类似的方式将基于64的字符串转换为对象,但是在运行时转换基于64的字符串,这会引发异常 flexjson.JSONException:期望a',&#39 ;或者']'在角色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;
}
}
答案 0 :(得分:0)
new String (Base64.decodeBase64(&#34; eyJyZWxhdGVzVG8iOiI3X1NlcHQyMDE3X0lGMDEifQ ==&#34; .getBytes()));
这将转换为正确的字符串。
我提到https://www.mkyong.com/java/how-do-convert-byte-array-to-string-in-java/