亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用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 關注
  • 2195 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號