为了账号安全,请及时绑定邮箱和手机立即绑定

使用JsonReader.setLenient(true)在第1行第1列路径$接受格式错误的JSON

使用JsonReader.setLenient(true)在第1行第1列路径$接受格式错误的JSON

慕后森 2019-12-26 13:46:11
这是什么错误?我怎样才能解决这个问题?我的应用程序正在运行,但无法加载数据。这是我的错误:使用JsonReader.setLenient(true)在第1行第1列路径$接受格式错误的JSON这是我的片段:public class news extends Fragment {private RecyclerView recyclerView;private ArrayList<Deatails> data;private DataAdapter adapter;private View myFragmentView;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    myFragmentView = inflater.inflate(R.layout.news, container, false);    initViews();    return myFragmentView;}private void initViews() {    recyclerView = (RecyclerView) myFragmentView.findViewById(R.id.card_recycler_view);    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity().getApplicationContext());    recyclerView.setHasFixedSize(true);    recyclerView.setLayoutManager(layoutManager);    data = new ArrayList<Deatails>();    adapter = new DataAdapter(getActivity(), data);    recyclerView.setAdapter(adapter);    new Thread()    {        public void run()        {            getActivity().runOnUiThread(new Runnable() {                @Override                public void run() {                    loadJSON();                }            });        }    }    .start();}private void loadJSON() {    if (isNetworkConnected()){        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);        OkHttpClient client = new OkHttpClient.Builder()                .addInterceptor(interceptor)                .retryOnConnectionFailure(true)                .connectTimeout(15, TimeUnit.SECONDS)                .build();        Gson gson = new GsonBuilder()                .setLenient()                .create();总是这个错误与您的json无关,可能是来自错误的请求,为了更好地处理,首先请在邮递员中检查您的请求(如果您得到了响应),然后将您的json响应与您的模型进行比较(如果没有错误的话),则该错误来自错误的请求,当您的响应未启动时也可能发生(在某些情况下响应可能是html)
查看完整描述

3 回答

?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

当响应内容类型不是时,也会发生此问题application/json。在我的情况下,响应内容类型为text/html,我遇到了这个问题。我将其更改为application/json工作。


查看完整回答
反对 回复 2019-12-26
  • 3 回答
  • 0 关注
  • 2003 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信