有人能告诉我如何获取此JSON文件的内容吗?
............................................... ....................
注意:我只想知道如何阅读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);
}
}
答案 0 :(得分:0)
@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;
}
现在它正在运作!