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