這是什么錯誤?我怎樣才能解決這個問題?我的應用程序正在運行,但無法加載數據。這是我的錯誤:使用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工作。
- 3 回答
- 0 關注
- 2195 瀏覽
添加回答
舉報
0/150
提交
取消
