4
fastjson-1.2.47,当Base64字符串中的斜杠/被转义为\/后,解析为byte[]有问题。
@JSONType
public class TestEntity {
@JSONField(name="type")
public int type;
@JSONField(name="data")
public byte[] data;
}
如下调用:
String j1 = "{\"type\":800,\"data\":\"HuYgMIxwfqdtvOJNv6kK025g5fh3yFHI2kaByO7udKk6FOBC3PGRWkGfwV0\\/vWQW6roN5ftKDHFZ3PWl0715OYue0rZj\\/VwrNsMvIL4MqTUNBBUGFU9SgZu87ss7RqmyijH6\\/sM968cK1Dv5U7Rrw79idl\\/hW8SILLn1YXvUa60=\"}";
try {
JSONObject y1 = JSON.parseObject(j1);
Log.e(TAG, "y1=" + y1);
TestEntity y2 = y1.toJavaObject(TestEntity.class);
Log.e(TAG, "y2=" + JSON.toJSONString(y2));
TestEntity y3 = JSON.parseObject(j1, TestEntity.class);
Log.e(TAG, "y3=" + JSON.toJSONString(y3));
} catch (Exception e) {
// TODO: handle exception
Log.e(TAG, "xx", e);
}
结果:
04-27 08:21:11.907: E/xx(14883): y1={"data":"HuYgMIxwfqdtvOJNv6kK025g5fh3yFHI2kaByO7udKk6FOBC3PGRWkGfwV0/vWQW6roN5ftKDHFZ3PWl0715OYue0rZj/VwrNsMvIL4MqTUNBBUGFU9SgZu87ss7RqmyijH6/sM968cK1Dv5U7Rrw79idl/hW8SILLn1YXvUa60=","type":800}
04-27 08:21:11.924: E/xx(14883): y2={"data":"HuYgMIxwfqdtvOJNv6kK025g5fh3yFHI2kaByO7udKk6FOBC3PGRWkGfwV0/vWQW6roN5ftKDHFZ3PWl0715OYue0rZj/VwrNsMvIL4MqTUNBBUGFU9SgZu87ss7RqmyijH6/sM968cK1Dv5U7Rrw79idl/hW8SILLn1YXvUa60=","type":800}
04-27 08:21:11.927: E/xx(14883): y3={"data":"HuYgMIxwfqdtvOJNv6kK025g5fh3yFHI2kaByO7udKk6FOBC3PGRWkGf/////vWQW6roN5ftKDHFZ3PWl0715OYue0rZ///VwrNsMvIL4MqTUNBBUGFU9SgZu87ss7Rqmyij////sM968cK1Dv5U7Rrw79id///hW8SILLn1YXvU","type":800}
其中y1和y2是正确的,而y3是错误的。