01-21 10:38:37.413: W/System.err(7864): com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 19, fieldName data
01-21 10:38:37.414: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:232)
01-21 10:38:37.414: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:135)
01-21 10:38:37.414: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:33)
01-21 10:38:37.414: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.parseField(JavaBeanDeserializer.java:420)
01-21 10:38:37.415: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:330)
01-21 10:38:37.415: W/System.err(7864): at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:135)
01-21 10:38:37.415: W/System.err(7864): at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:551)
01-21 10:38:37.415: W/System.err(7864): at com.alibaba.fastjson.JSONReader.readObject(JSONReader.java:189)
01-21 10:38:37.416: W/System.err(7864): at com.alibaba.fastjson.JSONReader.readObject(JSONReader.java:184)
public int code;
public String msg;
public T data;
服务器返回的数据为空的情况下报错即data=""
,但是如果不为空则没有问题
TypeReference<Response<User>> reference = new TypeReference<Response<User>>() {
};
我觉得这个问题你做一下异常处理不行么? 看这错误说的是语法问题:
W/System.err(7864): com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 19, fieldName data
第二种情况返回空数据,
FastJSON可以通过修改配置进行空字符串过滤
用了Spring的话可以在xml里配置
没有Spring的话在JSON.toJSONString(SerializerFeature.WriteMapNullValue)....... ),填入相应的参数
具体请看com.alibaba.fastjson.serializer
作用就是变量名,比如同时配置了
WriteMapNullValue
、WriteNullStringAsEmpty
,当容器里是NULL时JSON转化成""参考:
https://github.com/alibaba/fastjson/wiki