简体   繁体   English

使用离子库加载返回 null JsonObject 结果

[英]Loading using Ion Library returning null JsonObject result

I had built an Android app a few months back, in which one fragment was used to display news using News API.几个月前,我构建了一个 Android 应用程序,其中一个片段用于使用 News API 显示新闻。 Recently, when I ran the app again, the following error is occurring.最近,当我再次运行该应用程序时,出现以下错误。
错误

I am attaching the code snippet where the error is occurring.我附上了发生错误的代码片段。

Ion.with(getActivity()).load("GET",urltemp).asJsonObject().setCallback(new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {

                    Log.d(TAG, "enter ");
                    String status = result.get("status").getAsString();
                    if (status.equals("ok")) {

                        JsonArray array = result.get("articles").getAsJsonArray();

                        for (int i = 0; i < array.size(); i++) {
                            JsonObject object = array.get(i).getAsJsonObject();

                            String author = object.get("author").toString();

                            String title = object.get("title").toString();
                            title = title.substring(1, title.length() - 1);

                            String url = object.get("url").toString();
                            url = url.substring(1, url.length() - 1);

                            String urlToImage = object.get("urlToImage").toString();
                            urlToImage = urlToImage.substring(1, urlToImage.length() - 1);

                            String date = object.get("publishedAt").toString();
                            String content = object.get("content").toString();
                            content = content.substring(1, content.length() - 1);

                            items.add(new ModelItems(title, author, date, urlToImage, url));
                        }

                        adapter = new SlideshowViewModel(getActivity(), items);
                        recyclerView.setAdapter(adapter);

                        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
                        recyclerView.setLayoutManager(layoutManager);
                        Log.d(TAG, "success");
                    } else {
                        Log.e(TAG, "error");
                    }
                }
            });

Now, I thought there could be two possible sources of error, either it is a problem with URL( urltemp variable) or it is with Ion library.现在,我认为可能有两个可能的错误来源,要么是 URL( urltemp变量)的问题,要么是 Ion 库的问题。 Now, I pasted the URL in the browser, it is working fine.现在,我在浏览器中粘贴了 URL,它工作正常。 So, I guess the problem is with Ion.所以,我想问题出在离子上。 The JsonObject result is null always. JsonObject 结果始终为 null。 Tried different things, but can't figure out any solution.尝试了不同的东西,但无法找出任何解决方案。

I have never used Postman.我从未使用过 Postman。 So, I am not aware of how to post API response.所以,我不知道如何发布 API 响应。 I am attaching how i assigned URL.我附上了我如何分配 URL。

网址临时

A thing I tried is pasting the above URL in the browser.我尝试的一件事是在浏览器中粘贴上面的 URL 。 When I paste the URL in browser, I get the following response:当我在浏览器中粘贴 URL 时,我得到以下响应:回复

Seems like String status = result.get("status").getAsString();好像String status = result.get("status").getAsString(); is being returned null from your server.正在从您的服务器返回 null。 can you post a API response from postman你能发布来自 postman 的 API 回复吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM