用的是kotlin使用范例上面的内容,但是程序依然会崩溃。期待解决。
data class DataClass(@JSONField(name="aa")val a : Int, @JSONField(name="bb")val b : Int)
val dt = DataClass(1,2)
val json = JSON.toJSONString(dt)
logger.e(json)
val clz = DataClass::class
logger.e(clz.javaObjectType.toString())
val dt1 = JSON.parseObject(json,clz.javaObjectType)
logger.e(dt1.toString())
出错内容: Process: cn.ac.ia.iot.www.telemedicine, PID: 8718 com.alibaba.fastjson.JSONException: default constructor not found. class cn.ac.ia.iot.www.telemedicine.mvp.model.bean.DataClass at com.alibaba.fastjson.parser.JavaBeanInfo.build(JavaBeanInfo.java:496) at com.alibaba.fastjson.parser.JavaBeanDeserializer.(JavaBeanDeserializer.java:35) at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:229) at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:148) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:683) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:659) at com.alibaba.fastjson.JSON.parseObject(JSON.java:238) at com.alibaba.fastjson.JSON.parseObject(JSON.java:210) at com.alibaba.fastjson.JSON.parseObject(JSON.java:169) at com.alibaba.fastjson.JSON.parseObject(JSON.java:278) at cn.ac.ia.iot.www.telemedicine.mvp.presenter.ActivityLoginPresenter.attemptLogin(ActivityLoginPresenter.kt:44) at cn.ac.ia.iot.www.telemedicine.ui.activity.LoginActivity.attemptLogin(LoginActivity.kt:74) at cn.ac.ia.iot.www.telemedicine.ui.activity.LoginActivity.onClick(LoginActivity.kt:88) at android.view.View.performClick(View.java:4790) at android.view.View$PerformClick.run(View.java:19924) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5418) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1037) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)