【问题标题】:JSON - Blogger API - How to read text from a specific page?JSON - Blogger API - 如何从特定页面读取文本?
【发布时间】:2018-02-17 12:06:18
【问题描述】:

谁能告诉我如何获取这个 JSON 文件的内容?

.................................................. .....................

注意:我只想知道如何从 JSON 中读取 内容

.................................................. .....................

LINK TO JSON

{
 "kind": "blogger#page",
 "id": "myId01",
 "blog": {
  "id": "myId02"
 },
 "published": "2018-02-17T03:43:00-08:00",
 "updated": "2018-02-17T03:43:59-08:00",
 "etag": "\"mytag\"",
 "url": "http://my.blogspot.com/p/page.html",
 "selfLink": "https://www.googleapis.com/blogger/v3/blogs/BLOGID/pages/PAGEID",
 "title": "page",
 "content": "STACK OVERFLOW",
 "author": {
  "id": "myId03",
  "displayName": "MyName",
  "url": "https://www.blogger.com/profile/MyID",
  "image": {
   "url": "//lh5.googleusercontent.com/link/photo.jpg"
  }
 }
}

我想从 JSON 中读取 内容,我的代码(工作)。

.................................................. ......

private class GetText extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            ProviderHTTP sh = new ProviderHTTP();
            String jsonStr = sh.makeServiceCall(url);
            Log.e(TAG, "Response from url: " + jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    JSONArray items = jsonObj.getJSONArray("content");
///////////////////////// I'M confused HERE /////////////////////////
                    for (int i = 0; i < items.length(); i++) {
                        JSONObject c = items.getJSONObject(i);

                            text = c.getString("text");
                        }

                        toast.setText(text);
                        tost.show();

            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
        }
    }

【问题讨论】:

    标签: java android json google-api


    【解决方案1】:
         @Override
    protected Void doInBackground(Void... arg0) {
        ProviderHTTP sh = new ProviderHTTP();
        String jsonStr = sh.makeServiceCall(url);
        Log.e(TAG, "Response from url: " + jsonStr);
    
        if (jsonStr != null) {
            try {
                 JSONObject jsonObj = new JSONObject(jsonStr);
                 String content = jsonObj.getString("content");
                 Looper.prepare();
                 toast.setText(content);
                 tost.show();
        }
        return null;
    }
    

    现在它开始工作了!

    【讨论】:

    • 那么toast.setText(content);?好吧,让我试试
    • 如果没问题..标记答案......@ArghadipDasCEO..或者如果您有任何问题请告诉我
    • 字符串内容 = jsonStr.getString("content"); getString 显示错误
    • 我无法看到你的完整 json ..你能发布所有的
    • 我发布了完整的 JSON
    猜你喜欢
    • 2023-04-01
    • 2012-11-13
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 2020-03-14
    • 1970-01-01
    相关资源
    最近更新 更多