gson.internal.LinkedTreeMap如何转化成javabean对象?

我有一个基础的数据类型(所有服务器返回的数据都是这个格式,只是data类型不同而已)

 public class BaseDataEntity{
    private String result;
    private String msg;
    private Object data;

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

我在Gson解析完返回数据中想要这样使用:

      mData = (BaseDataEntity) msg.obj;//这个可以正常转换
      UserEntity entity = (UserEntity) mData.getData();

可是这时候便会报出com.google.gson.internal.LinkedTreeMap无法转换成UserEntity这个类的错误,我想问一下有什么方法可以解决吗?

2个回答

先把linkedTreeMap对象转成json字符串,然后再转成JavaBean

Gson gson = new Gsonbuilder.enableComplexMapKeySerialization().create();
String jsonString = gson.toJson(linkedTreeMap);
JavaBean bean = gson.fromJson(jsonString,JavaBean.class);

hottest518
拾荒者老大 然并卵
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
gson解析对象数组,使用泛型封装报错

问题如下: ``` java public class App { public static void main(String[] args) { List<User> userList = new ArrayList<>(); String json = "[{\"uid\":1,\"username\":\"user1\",\"password\":\"user1\",\"type\":\"普通\"}," + "{\"uid\":2,\"username\":\"user2\",\"password\":\"user2\",\"type\":\"普通\"}," + "{\"uid\":3,\"username\":\"user3\",\"password\":\"user3\",\"type\":\"普通\"}]"; userList = jsonToBeanList(json, User.class); // 这个地方报错:java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap // cannot be cast to com.hezhujun.match.pojo.User for (User user : userList) { System.out.println(user); } } public static <T> List<T> jsonToBeanList(String json, Class<T> clas) { Gson gson = new Gson(); List<T> list = gson.fromJson(json, new TypeToken<List<T>>() { }.getType()); // 这个地方可以正常打印 for (T t : list) { System.out.println(t); } return list; } /* 运行之后控制台输出的信息 {uid=1.0, username=user1, password=user1, type=普通} Exception in thread "main" {uid=2.0, username=user2, password=user2, type=普通} {uid=3.0, username=user3, password=user3, type=普通} java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.hezhujun.match.pojo.User at com.hezhujun.match.util.App.main(App.java:22) */ } ```

坐等求救,java用ssh的时候,Gson解析json有外键的时候报错

解析json是用的gson,实体类涉及到三张表三个类,之间的关系是: C表的一个字段是外键,为A表的主键 C表的另一个字段是外键,为B表的主键 转json的时候报如下异常,该怎么做,请具体一点. 这是多对多的关系吧? java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter? at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:67) at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:61) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.ArrayTypeAdapter.write(ArrayTypeAdapter.java:93) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195) at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:107) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195) at com.google.gson.Gson.toJson(Gson.java:593) at com.google.gson.Gson.toJson(Gson.java:572) at com.google.gson.Gson.toJson(Gson.java:527) at com.chebeiyuan.utils.GsonUtil.objectToString(GsonUtil.java:29) at com.chebeiyuan.action.BaseAction.setResultJson(BaseAction.java:136) at com.chebeiyuan.action.BaseAction.setSuccessJson(BaseAction.java:149) at com.chebeiyuan.action.CarTypeAction.getUserCarList(CarTypeAction.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Thread.java:619)

在网络请求的时候出现以下报错

遇到了这么个问题,用的Retrofit+rxjava+Okhttp,求解答 ``` Process: com.example.tidus.ristrat, PID: 7166 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tidus.ristrat/com.example.tidus.ristrat.activity.RiskAssessmentActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.example.tidus.ristrat.bean.RiskAssessmentBean for method IRetrofitServer.doRiskTableListGet at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7319) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934) Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.example.tidus.ristrat.bean.RiskAssessmentBean for method IRetrofitServer.doRiskTableListGet at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:755) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:741) at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:172) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170) at retrofit2.Retrofit$1.invoke(Retrofit.java:147) at java.lang.reflect.Proxy.invoke(Proxy.java:1006) at $Proxy3.doRiskTableListGet(Unknown Source) at com.example.tidus.ristrat.mvp.model.RiskAssessmentModel.getRiskAssessment(RiskAssessmentModel.java:25) at com.example.tidus.ristrat.mvp.presenter.RiskAssessmentPresenter.getRiskAssessment(RiskAssessmentPresenter.java:16) at com.example.tidus.ristrat.activity.RiskAssessmentActivity.initPresenterData(RiskAssessmentActivity.java:183) at com.example.tidus.ristrat.activity.RiskAssessmentActivity.initData(RiskAssessmentActivity.java:158) at com.example.lib_core.base.BaseActivity.onCreate(BaseActivity.java:44) at android.app.Activity.performCreate(Activity.java:7783) at android.app.Activity.performCreate(Activity.java:7772) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235) ... 11 more Caused by: java.lang.SecurityException: Can not make a java.lang.reflect.Method constructor accessible at java.lang.reflect.AccessibleObject.setAccessible0(AccessibleObject.java:153) at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:132) at com.google.gson.internal.reflect.PreJava9ReflectionAccessor.makeAccessible(PreJava9ReflectionAccessor.java:31) at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:103) at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:85) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:101) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ArrayTypeAdapter$1.create(ArrayTypeAdapter.java:48) at com.google.gson.Gson.getAdapter(Gson.java:458) 2019-09-04 13:57:04.536 7166-7166/com.example.tidus.ristrat E/AndroidRuntime: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117) 2019-09-04 13:57:04.537 7166-7166/com.example.tidus.ristrat E/AndroidRuntime: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:64) at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330) at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:739) ... 25 more ``` Bean类 ``` package com.example.tidus.ristrat.bean; import android.view.View; import java.io.Serializable; import java.util.List; public class RiskAssessmentBean implements Serializable { private String code; private String message; private String server_code; private ServerParamsBean server_params; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getServer_code() { return server_code; } public void setServer_code(String server_code) { this.server_code = server_code; } public ServerParamsBean getServer_params() { return server_params; } public void setServer_params(ServerParamsBean server_params) { this.server_params = server_params; } public static class ServerParamsBean implements Serializable { private String PATIENT_ID; private Object DOCTOR_NAME; private Object REPORT_CODE; private Object REPORT_ID; private String IN_DEPT_CODE; private String IN_DEPT_NAME; private String PATIENT_NAME; private String BIRTHDAY; private String PATIENT_SEX; private String MEDICAL_REC_NUMBER; private String VISIT_SQ_NO; private String BED_NUMBER; private List<WENJUANNAMEBean> WENJUANNAME; public String getPATIENT_ID() { return PATIENT_ID; } public void setPATIENT_ID(String PATIENT_ID) { this.PATIENT_ID = PATIENT_ID; } public Object getDOCTOR_NAME() { return DOCTOR_NAME; } public void setDOCTOR_NAME(Object DOCTOR_NAME) { this.DOCTOR_NAME = DOCTOR_NAME; } public Object getREPORT_CODE() { return REPORT_CODE; } public void setREPORT_CODE(Object REPORT_CODE) { this.REPORT_CODE = REPORT_CODE; } public Object getREPORT_ID() { return REPORT_ID; } public void setREPORT_ID(Object REPORT_ID) { this.REPORT_ID = REPORT_ID; } public String getIN_DEPT_CODE() { return IN_DEPT_CODE; } public void setIN_DEPT_CODE(String IN_DEPT_CODE) { this.IN_DEPT_CODE = IN_DEPT_CODE; } public String getIN_DEPT_NAME() { return IN_DEPT_NAME; } public void setIN_DEPT_NAME(String IN_DEPT_NAME) { this.IN_DEPT_NAME = IN_DEPT_NAME; } public String getPATIENT_NAME() { return PATIENT_NAME; } public void setPATIENT_NAME(String PATIENT_NAME) { this.PATIENT_NAME = PATIENT_NAME; } public String getBIRTHDAY() { return BIRTHDAY; } public void setBIRTHDAY(String BIRTHDAY) { this.BIRTHDAY = BIRTHDAY; } public String getPATIENT_SEX() { return PATIENT_SEX; } public void setPATIENT_SEX(String PATIENT_SEX) { this.PATIENT_SEX = PATIENT_SEX; } public String getMEDICAL_REC_NUMBER() { return MEDICAL_REC_NUMBER; } public void setMEDICAL_REC_NUMBER(String MEDICAL_REC_NUMBER) { this.MEDICAL_REC_NUMBER = MEDICAL_REC_NUMBER; } public String getVISIT_SQ_NO() { return VISIT_SQ_NO; } public void setVISIT_SQ_NO(String VISIT_SQ_NO) { this.VISIT_SQ_NO = VISIT_SQ_NO; } public String getBED_NUMBER() { return BED_NUMBER; } public void setBED_NUMBER(String BED_NUMBER) { this.BED_NUMBER = BED_NUMBER; } public List<WENJUANNAMEBean> getWENJUANNAME() { return WENJUANNAME; } public void setWENJUANNAME(List<WENJUANNAMEBean> WENJUANNAME) { this.WENJUANNAME = WENJUANNAME; } public static class WENJUANNAMEBean implements Serializable { private int MERCHANT_ID; private int SITE_ID; private int DEPARTMENT; private int FORM_ID; private String FORM_NAME; private int FORM_TYPE; private int FORM_SEQ; private String BUSINESS_CLASS; private List<XUANXIANGBean> XUANXIANG; private boolean che_color; private int form_id; public int getForm_id() { return form_id; } public void setForm_id(int form_id) { this.form_id = form_id; } public boolean isChe_color() { return che_color; } public void setChe_color(boolean che_color) { this.che_color = che_color; } public int getMERCHANT_ID() { return MERCHANT_ID; } public void setMERCHANT_ID(int MERCHANT_ID) { this.MERCHANT_ID = MERCHANT_ID; } public int getSITE_ID() { return SITE_ID; } public void setSITE_ID(int SITE_ID) { this.SITE_ID = SITE_ID; } public int getDEPARTMENT() { return DEPARTMENT; } public void setDEPARTMENT(int DEPARTMENT) { this.DEPARTMENT = DEPARTMENT; } public int getFORM_ID() { return FORM_ID; } public void setFORM_ID(int FORM_ID) { this.FORM_ID = FORM_ID; } public String getFORM_NAME() { return FORM_NAME; } public void setFORM_NAME(String FORM_NAME) { this.FORM_NAME = FORM_NAME; } public int getFORM_TYPE() { return FORM_TYPE; } public void setFORM_TYPE(int FORM_TYPE) { this.FORM_TYPE = FORM_TYPE; } public int getFORM_SEQ() { return FORM_SEQ; } public void setFORM_SEQ(int FORM_SEQ) { this.FORM_SEQ = FORM_SEQ; } public String getBUSINESS_CLASS() { return BUSINESS_CLASS; } public void setBUSINESS_CLASS(String BUSINESS_CLASS) { this.BUSINESS_CLASS = BUSINESS_CLASS; } public List<XUANXIANGBean> getXUANXIANG() { return XUANXIANG; } public void setXUANXIANG(List<XUANXIANGBean> XUANXIANG) { this.XUANXIANG = XUANXIANG; } public static class XUANXIANGBean implements Serializable { private String GROUP_TAB; private int GROUP_TAB_ID; private List<WENJUANBean> WENJUAN; public String getGROUP_TAB() { return GROUP_TAB; } public void setGROUP_TAB(String GROUP_TAB) { this.GROUP_TAB = GROUP_TAB; } public int getGROUP_TAB_ID() { return GROUP_TAB_ID; } public void setGROUP_TAB_ID(int GROUP_TAB_ID) { this.GROUP_TAB_ID = GROUP_TAB_ID; } public List<WENJUANBean> getWENJUAN() { return WENJUAN; } public void setWENJUAN(List<WENJUANBean> WENJUAN) { this.WENJUAN = WENJUAN; } public static class WENJUANBean implements Serializable { private int FACTOR_GROUP_SEQ; private String FACTOR_GROUP_ID; private String FACTOR_GROUP_NAME; private List<SublistBean> sublist; public int getFACTOR_GROUP_SEQ() { return FACTOR_GROUP_SEQ; } public void setFACTOR_GROUP_SEQ(int FACTOR_GROUP_SEQ) { this.FACTOR_GROUP_SEQ = FACTOR_GROUP_SEQ; } public String getFACTOR_GROUP_ID() { return FACTOR_GROUP_ID; } public void setFACTOR_GROUP_ID(String FACTOR_GROUP_ID) { this.FACTOR_GROUP_ID = FACTOR_GROUP_ID; } public String getFACTOR_GROUP_NAME() { return FACTOR_GROUP_NAME; } public void setFACTOR_GROUP_NAME(String FACTOR_GROUP_NAME) { this.FACTOR_GROUP_NAME = FACTOR_GROUP_NAME; } public List<SublistBean> getSublist() { return sublist; } public void setSublist(List<SublistBean> sublist) { this.sublist = sublist; } public static class SublistBean implements Serializable { private int FACTOR_GROUP_ID; private String FACTOR_GROUP_NAME; private String FACTOR_GROUP_DESC; private int FACTOR_GROUP_SEQ; private Object GROUP_SHOW_LAYOUT; private int RISK_FACTOR_ID; private String RISK_FACTOR_NAME; private int SCORE_SHOW_TYPE; private int MUTEX_GROUP; private String isslect; private String ANALYSIS_SOURCE_STR; private String CURRENT_DESC; private List<OptionListBean> optionList; private View shuruValue; private boolean checked; public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } public View getShuruValue() { return shuruValue; } public void setShuruValue(View shuruValue) { this.shuruValue = shuruValue; } public int getFACTOR_GROUP_ID() { return FACTOR_GROUP_ID; } public void setFACTOR_GROUP_ID(int FACTOR_GROUP_ID) { this.FACTOR_GROUP_ID = FACTOR_GROUP_ID; } public String getFACTOR_GROUP_NAME() { return FACTOR_GROUP_NAME; } public void setFACTOR_GROUP_NAME(String FACTOR_GROUP_NAME) { this.FACTOR_GROUP_NAME = FACTOR_GROUP_NAME; } public String getFACTOR_GROUP_DESC() { return FACTOR_GROUP_DESC; } public void setFACTOR_GROUP_DESC(String FACTOR_GROUP_DESC) { this.FACTOR_GROUP_DESC = FACTOR_GROUP_DESC; } public int getFACTOR_GROUP_SEQ() { return FACTOR_GROUP_SEQ; } public void setFACTOR_GROUP_SEQ(int FACTOR_GROUP_SEQ) { this.FACTOR_GROUP_SEQ = FACTOR_GROUP_SEQ; } public Object getGROUP_SHOW_LAYOUT() { return GROUP_SHOW_LAYOUT; } public void setGROUP_SHOW_LAYOUT(Object GROUP_SHOW_LAYOUT) { this.GROUP_SHOW_LAYOUT = GROUP_SHOW_LAYOUT; } public int getRISK_FACTOR_ID() { return RISK_FACTOR_ID; } public void setRISK_FACTOR_ID(int RISK_FACTOR_ID) { this.RISK_FACTOR_ID = RISK_FACTOR_ID; } public String getRISK_FACTOR_NAME() { return RISK_FACTOR_NAME; } public void setRISK_FACTOR_NAME(String RISK_FACTOR_NAME) { this.RISK_FACTOR_NAME = RISK_FACTOR_NAME; } public int getSCORE_SHOW_TYPE() { return SCORE_SHOW_TYPE; } public void setSCORE_SHOW_TYPE(int SCORE_SHOW_TYPE) { this.SCORE_SHOW_TYPE = SCORE_SHOW_TYPE; } public int getMUTEX_GROUP() { return MUTEX_GROUP; } public void setMUTEX_GROUP(int MUTEX_GROUP) { this.MUTEX_GROUP = MUTEX_GROUP; } public String getIsslect() { return isslect; } public void setIsslect(String isslect) { this.isslect = isslect; } public String getANALYSIS_SOURCE_STR() { return ANALYSIS_SOURCE_STR; } public void setANALYSIS_SOURCE_STR(String ANALYSIS_SOURCE_STR) { this.ANALYSIS_SOURCE_STR = ANALYSIS_SOURCE_STR; } public String getCURRENT_DESC() { return CURRENT_DESC; } public void setCURRENT_DESC(String CURRENT_DESC) { this.CURRENT_DESC = CURRENT_DESC; } public List<OptionListBean> getOptionList() { return optionList; } public void setOptionList(List<OptionListBean> optionList) { this.optionList = optionList; } public static class OptionListBean implements Serializable { private int RISK_FACTOR_ID; private int FACTOR_OPTION_ID; private String FACTOR_OPTION; private String OPTION_TYPE; private Object VALUE_START; private Object VALUE_END; private Object SEX; private int AGE_BEGIN; private int AGE_END; private int RISK_SCORE; private int CHANGE_FLAG; private Object RISK_SCORE_CHANGE; private int RISK_LEVEL; private Object DISEASE_CODE; private Object BAD_HABITS; private Object BAD_HABITS_DESC; private Object BAD_HABITS_IMPROVE; private boolean itemChecked; public boolean isItemChecked() { return itemChecked; } public void setItemChecked(boolean itemChecked) { this.itemChecked = itemChecked; } public int getRISK_FACTOR_ID() { return RISK_FACTOR_ID; } public void setRISK_FACTOR_ID(int RISK_FACTOR_ID) { this.RISK_FACTOR_ID = RISK_FACTOR_ID; } public int getFACTOR_OPTION_ID() { return FACTOR_OPTION_ID; } public void setFACTOR_OPTION_ID(int FACTOR_OPTION_ID) { this.FACTOR_OPTION_ID = FACTOR_OPTION_ID; } public String getFACTOR_OPTION() { return FACTOR_OPTION; } public void setFACTOR_OPTION(String FACTOR_OPTION) { this.FACTOR_OPTION = FACTOR_OPTION; } public String getOPTION_TYPE() { return OPTION_TYPE; } public void setOPTION_TYPE(String OPTION_TYPE) { this.OPTION_TYPE = OPTION_TYPE; } public Object getVALUE_START() { return VALUE_START; } public void setVALUE_START(Object VALUE_START) { this.VALUE_START = VALUE_START; } public Object getVALUE_END() { return VALUE_END; } public void setVALUE_END(Object VALUE_END) { this.VALUE_END = VALUE_END; } public Object getSEX() { return SEX; } public void setSEX(Object SEX) { this.SEX = SEX; } public int getAGE_BEGIN() { return AGE_BEGIN; } public void setAGE_BEGIN(int AGE_BEGIN) { this.AGE_BEGIN = AGE_BEGIN; } public int getAGE_END() { return AGE_END; } public void setAGE_END(int AGE_END) { this.AGE_END = AGE_END; } public int getRISK_SCORE() { return RISK_SCORE; } public void setRISK_SCORE(int RISK_SCORE) { this.RISK_SCORE = RISK_SCORE; } public int getCHANGE_FLAG() { return CHANGE_FLAG; } public void setCHANGE_FLAG(int CHANGE_FLAG) { this.CHANGE_FLAG = CHANGE_FLAG; } public Object getRISK_SCORE_CHANGE() { return RISK_SCORE_CHANGE; } public void setRISK_SCORE_CHANGE(Object RISK_SCORE_CHANGE) { this.RISK_SCORE_CHANGE = RISK_SCORE_CHANGE; } public int getRISK_LEVEL() { return RISK_LEVEL; } public void setRISK_LEVEL(int RISK_LEVEL) { this.RISK_LEVEL = RISK_LEVEL; } public Object getDISEASE_CODE() { return DISEASE_CODE; } public void setDISEASE_CODE(Object DISEASE_CODE) { this.DISEASE_CODE = DISEASE_CODE; } public Object getBAD_HABITS() { return BAD_HABITS; } public void setBAD_HABITS(Object BAD_HABITS) { this.BAD_HABITS = BAD_HABITS; } public Object getBAD_HABITS_DESC() { return BAD_HABITS_DESC; } public void setBAD_HABITS_DESC(Object BAD_HABITS_DESC) { this.BAD_HABITS_DESC = BAD_HABITS_DESC; } public Object getBAD_HABITS_IMPROVE() { return BAD_HABITS_IMPROVE; } public void setBAD_HABITS_IMPROVE(Object BAD_HABITS_IMPROVE) { this.BAD_HABITS_IMPROVE = BAD_HABITS_IMPROVE; } } } } } } } } ``` 网络请求的时候 doRiskTableListGet()这个方法报错 ``` public class RiskAssessmentModel implements IRiskAssessmentContart.IRiskAssessmentModel { @SuppressLint("CheckResult") @Override public void getRiskAssessment(HashMap<String, Object> params, final IRequestCallback iRequestCallback) { RetrofitUtils.getInstance().createService(IRetrofitServer.class) .doRiskTableListGet(ApiService.RISK_TABLE_LIST, params) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<RiskAssessmentBean>() { @Override public void accept(RiskAssessmentBean riskAssessmentBean) throws Exception { if (iRequestCallback != null) { iRequestCallback.onSuccess(riskAssessmentBean); } } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { if (iRequestCallback != null) { iRequestCallback.onFailed(throwable); } } }); } ``` 这是我进到doRiskTableListGet()方法内的代码 ``` @GET Observable<RiskAssessmentBean> doRiskTableListGet(@Url String apiUrl, @QueryMap HashMap<String, Object> params); ```

ClassNotFoundException: com.google.gson.Gson

Servlet.service() for servlet [ns] in context with path [/EC] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/google/gson/Gson] with root cause java.lang.ClassNotFoundException: com.google.gson.Gson at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) at com.ns.controllers.impl.systemDevice.SystemManageImpl.SendDeviceControlOrder(SystemManageImpl.java:307) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

gson将json格式的字符串转成java对象,json字符串中long怎么转变不会报错?

# gson将json格式的字符串转成java对象,json字符串中long怎么转变不会报错? public static void main(String[] args) { long timel=12323232L; SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time=sdf.format(timel); System.out.println(time);//正常 Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); String obj="[{\"name\":\"caochuankui\",\"time\":"+timel+"}]"; JSONArray objo=new JSONArray(obj); GsonTest gt=gson.fromJson(objo.toString(), GsonTest.class);//报错 System.out.println(gt.getTime()); } } 错误信息如下: 1970-01-01 11:25:23 Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $ at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200) at com.google.gson.Gson.fromJson(Gson.java:810) at com.google.gson.Gson.fromJson(Gson.java:775) at com.google.gson.Gson.fromJson(Gson.java:724) at com.google.gson.Gson.fromJson(Gson.java:696) at com.pagecofig.util.GsonTest.main(GsonTest.java:67) Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $ at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:189) ... 5 more 这要怎么解决,求大神指点

com.google.gson.JsonSyntaxException

我使用的是谷歌提供的gson解析json数据。json数据如下" {"flag":"0","data":{"id":"176","loginName":"18224006722","name":"18224006722","phone":"18224006722","mobile":"18224006722","loginToken":"c4b23c48bcc7a9bf4f4301cfeca4c3d2","isStoreAdm":"1","storeLogo":""},"tcount":0} ";网络方面我使用的是 OkHttpUtils。 使用自定义的 StringCallback() public abstract class LoginCall extends Callback<Login>{ @Override public Login parseNetworkResponse(Response response) throws Exception { String result = response.body().string(); Gson gson=new Gson(); return gson.fromJson(result,Login.class); } } java实体类我使用的是GsonFormat自动生成的而且还序列化了的,结果就是要报这个异常,求解答。 哦哦,我不使用gson解析可以获取到json字符串, java实体类: public class Login implements Serializable{ private String flag; private DataBean data; private int tcount; public String getFlag() { return flag; } public void setFlag(String flag) { this.flag = flag; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public int getTcount() { return tcount; } public void setTcount(int tcount) { this.tcount = tcount; } public static class DataBean implements Serializable{ private String id; private String loginName; private String name; private String phone; private String mobile; private String loginToken; private String isStoreAdm; private String storeLogo; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLoginName() { return loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getLoginToken() { return loginToken; } public void setLoginToken(String loginToken) { this.loginToken = loginToken; } public String getIsStoreAdm() { return isStoreAdm; } public void setIsStoreAdm(String isStoreAdm) { this.isStoreAdm = isStoreAdm; } public String getStoreLogo() { return storeLogo; } public void setStoreLogo(String storeLogo) { this.storeLogo = storeLogo; } } 求帮助呀,谢谢大神了。

求大神帮我com.google.gson.stream.MalformedJsonException

我别的界面用的解析方法都是一样的,别的界面的数据就是能解析出来,但是这个界面总是出现![图片说明](https://img-ask.csdn.net/upload/201607/29/1469756038_409519.png)![图片说明](https://img-ask.csdn.net/upload/201607/29/1469756049_973899.png)这个问题,但是那个JSON的格式又没有错,这问题已经卡了好几天了,望大神帮我解决一下,万分感谢

解析包含null的原始json数组

Json数组: {"userName":null," msgArr":[null],"numrow":0} //String result Gson: new Gson().fromJson(result, MyClass.class); MyClass: public String userName; public int[] msgArr; ... 错误stack: at java.lang.IllegalArgumentException: Primitive array can't take null values. at java.lang.reflect.Array.set(Array.java:406) at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:78) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) at com.google.gson.Gson.fromJson(Gson.java:803) at com.google.gson.Gson.fromJson(Gson.java:768) at com.google.gson.Gson.fromJson(Gson.java:717) at com.google.gson.Gson.fromJson(Gson.java:689) at com.test.dao.RequestBase.onPostExecute(RequestBase.java:79) 如果不能修改json字符串 "msgArr=[null]",怎么解除这个异常?

com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 232?

GSON解析json格式字符串,利用GSON的fromJson函数,将Json字符串解析为java对象,spark本地模式可以执行,但是在集群上yarn模式一直出现以下错误: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 232

renren-fast 框架集成云通讯短信sdk Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement;

renren-fast 框架,使用了云通讯的短信sdk后,调用短信发送,报错这个,不知道怎么处理 短信sdk https://doc.yuntongxun.com/p/5e1595e4d8130bd800fdb327 org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement; at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:112) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at io.renren.common.xss.XssFilter.doFilter(XssFilter.java:30) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:141) at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:82) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

Gson解析json报错。。。

com.google.gson.JsonParseException: The JsonDeserializer MapTypeAdapter failed to deserialized json object。在我朋友那运行没问题 ,我这运行就报这个错

坐等求救,java用ssh的时候,Gson解析json有外键的时候报错

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter? com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:73) com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:69) com.google.gson.TypeAdapter$1.write(TypeAdapter.java:191) com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) com.google.gson.internal.bind.ArrayTypeAdapter.write(ArrayTypeAdapter.java:95) com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:125) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:243) com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:125) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:243) com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:125) com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:243) com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:107) com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97) com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61) com.google.gson.Gson.toJson(Gson.java:669) com.google.gson.Gson.toJson(Gson.java:648) com.google.gson.Gson.toJson(Gson.java:603) com.google.gson.Gson.toJson(Gson.java:583) com.gx.lyf.other.controls.NoticeAction.text(NoticeAction.java:96) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

GSON使用toJson方法将类转为json格式字符串时的问

我在使用GSON使用toJson方法将类转为json格式字符串时* 自己定了一个对象。 Bean b=new bean(); b.setCard_id("XXXXXXXXXXXXX"); b.setMoney(3000); 调用 gson.toJson(b);是没啥问题,但是 Bean里面还设置了其他的 ,int型,例如 add_money。 但是转换出来的json语句就是{"card_id":"XXXXXXXXXXXXX","money":3000,"add_money":0} 有什么办法,规定,没有set的值不用输出 0吗?

servlet中Gson转换Json数据为对象,获取对象属性时报空指针问题,求解答

服务端获取的json字符串如下:{"name":"王五","course":{"chinese":70,"english":90}}; 转化成student对象,代码如下: package sourceCode; import java.io.BufferedReader; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.gson.Gson; public class TestJson extends HttpServlet{ public void doPost(HttpServletRequest res,HttpServletResponse req) throws IOException{ req.setHeader("Content-Type", "application/json;charset=utf-8"); BufferedReader br = res.getReader(); StringBuffer sb = new StringBuffer(); String str; while((str=br.readLine())!=null){ sb.append(str); } String jsonStr = sb.toString(); System.out.println("sb为:"+jsonStr); br.close(); Gson gson = new Gson(); Student stu = gson.fromJson(jsonStr, Student.class); System.out.println(stu.getName); System.out.println(stu.getCourse().getChinese()); } } student和sourse类代码如下: public class Student { private String name; private Course course; public Student() { super(); } public Student(String name, Course course) { super(); this.name = name; this.course = course; } //此处省略set和get函数 } public class Course { private int chinese; private int english; public Course() { super(); } public Course(int chinese, int english) { super(); this.chinese = chinese; this.english = english; } //此处省略set和get函数 } 当前台发起请求servlet时,控制台打印出的结果如下: ![图片说明](https://img-ask.csdn.net/upload/201803/18/1521382594_157346.png)

java上使用Gson转换长数字的字符串时,被当成了数字处理

直接上代码 public static void main(String[] args) { String jsonString="{\"list\":[{\"Arrayname\": \"000292603088\",\"LUNID\": \"09FB\",\"Capacity\": \"134.8681640625\",\"UUID\": \"60000970000292603088533030394642\",\"Mode\": \"vmax\"}," + "{ \"Arrayname\": \"000292603088\",\"LUNID\":\"09EB\",\"Capacity\":\"134.8681640625\",\"UUID\": \"60000970000292603088533030394542\",\"Mode\":\"vmax\"}]}"; Gson gson = new Gson(); Map<String, Object > itemmapMap=gson.fromJson(jsonString, Map.class); String tolist= itemmapMap.get("list").toString(); System.out.println("原始信息:"+tolist); List<Map<String, Object>> listjson =gson.fromJson(tolist, List.class); for (int i = 0; i < listjson.size(); i++) { Map<String, Object> itemMap=new HashMap<String, Object>(); itemMap=listjson.get(i); Map<String, String> insertMap=new HashMap<String, String>(); insertMap.put("lunId", itemMap.get("UUID").toString()); System.out.println("转换成了:"+insertMap.get("lunId")); } } 原始信息:[{Arrayname=000292603088, LUNID=09FB, Capacity=134.8681640625, UUID=60000970000292603088533030394642, Mode=vmax}, {Arrayname=000292603088, LUNID=09EB, Capacity=134.8681640625, UUID=60000970000292603088533030394542, Mode=vmax}] 转换成了:6.00009700002926E31 转换成了:6.00009700002926E31 请大神指点,希望数据变成60000970000292603088533030394542,而不是6.00009700002926E31 请问gson是否能指定字段的转换类型

:Expected BEGIN_ARRAY求大神们

12-03 01:40:58.903 3439-3456/? E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.h954gmail.y.cnch, PID: 3439 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ at com.google.gson.Gson.fromJson(Gson.java:899) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.h954gmail.y.cnch.fragment.HomeFragment$1.onResponse(HomeFragment.java:88) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61) at com.google.gson.Gson.fromJson(Gson.java:887) at com.google.gson.Gson.fromJson(Gson.java:852)  at com.google.gson.Gson.fromJson(Gson.java:801)  at com.h954gmail.y.cnch.fragment.HomeFragment$1.onResponse(HomeFragment.java:88)  at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)  at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)  at java.lang.Thread.run(Thread.java:818)  求解!!

gson转换字符型的日期 date问题

前端传的"yyyy-MM-dd HH:mm:ss" 格式的字符串 ,后台转换不了:org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: The date should be a string value; nested exception is com.google.gson.JsonParseException: The date should be a string value 后台数据date传到前端 转换成 "yyyy-MM-dd HH:mm:ss" ,但是前端"yyyy-MM-dd HH:mm:ss"传到后端 gson解析不了 。 但是 前端传这种格式就能解析转成date :"2018-08-22T02:44:09.647Z"

Gson解析json数据返回空值

方法1: String str = object.toString(); Gson gson = new GsonBuilder().create(); complaintDetail = gson.fromJson(str, ComplaintDetail.class); ``` 方法2: if (object.has("node")) { complaintDetail.setNode(object.getString("node")); } if (object.has("operateStarttime")) { complaintDetail.setOperateStarttime(object .getString("operateStarttime")); } if (object.has("operateDepartment")) { complaintDetail.setOperateDepartment(object .getString("operateDepartment")); } ``` 采用方法1解析,如果这个app采用了签名 就会显示不出这条数据,不签名则可以正常显示数据,这个数据是通过接口获取的,但是采用方法2解析则不会出现问题,那么 使用Gson解析需要有什么注意的吗 或者是有什么限制条件吗,

使用Gson框架制作Json时遇到的字符转义问题

第一次做后台遇到一个Json格式的问题,刚开始得到的JsonArray格式如下: [{"id":8,"account":"123456","password":"123456","name":"啦啦啦"},{"id":9,"account":"10086","password":"123456","name":"哈哈哈"}] 在返回给前端时需要弄成一个JsonObject,于是我写了一个实体类ReturnData,里面只有一个String data,然后使用Gson中的方法(json就是上面的jsonArray): ``` ReturnData returnData = new ReturnData(json); String gsonResult = gson.toJson(returnData); ``` 但是在转换时,Gson自动帮我添加了转义字符,最后结果如下: {"data":"[{\"id\":8,\"account\":\"123456\",\"password\":\"123456\",\"name\":\"啦啦啦\"} 有没有大神知道为什么会自动出现这样的转义字符,以及好一点的解决办法。

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

立即提问
相关内容推荐