我想解析這個JSON。如何解析Android中的JSON文檔?
JSON響應here
我不是在日誌貓只是鏈接獲取完整JSON數據
的AsyncTask
public class FetchMangaTask extends AsyncTask<String,Void,String[]>{
private final String LOG_TAG = FetchMangaTask.class.getSimpleName();
private String[] getMangaDataFromJson(String mangaJsonStr, int pages) throws JSONException{
final String MANGA_LIST = "manga";
final String MANGA_TITLE = "t";
final String MANGA_ID = "i";
JSONObject mangaJson = new JSONObject(mangaJsonStr);
JSONArray mangaArray = mangaJson.getJSONArray(MANGA_LIST);
String[] resultStr = new String[pages];
for (int i = 0; i <mangaArray.length(); i++){
JSONObject manga = mangaArray.getJSONObject(i);
String title = manga.getString(MANGA_TITLE);
String id = manga.getString(MANGA_ID);
}
for (String s : resultStr){
Log.v(LOG_TAG,"Manga Entry" + s);
}
return resultStr;
}
@Override
protected String[] doInBackground(String... params) {
if (params.length == 0){
return null;
}
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
String mangaJsonStr = null;
int pages = 1;
try {
final String MANGA_BASE_URL = "https://www.mangaeden.com/api/list/0/?";
final String PAGES_PARAM = "p";
Uri builtUri = Uri.parse(MANGA_BASE_URL).buildUpon()
.appendQueryParameter(PAGES_PARAM, Integer.toString(pages))
.build();
URL url = new URL(builtUri.toString());
Log.v(LOG_TAG, "Built URI " + builtUri.toString());
urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputStream == null){
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine())!= null){
buffer.append(line + "\n");
}
if (buffer.length() == 0){
return null;
}
mangaJsonStr = buffer.toString();
}catch (IOException e){
Log.e(LOG_TAG, "Error", e);
return null;
}finally {
if (urlConnection != null){
urlConnection.disconnect();
}
if (reader != null){
try{
reader.close();
}catch (final IOException e){
Log.e(LOG_TAG,"Error closing stream", e);
}
}
try {
return getMangaDataFromJson(mangaJsonStr, pages);
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
e.printStackTrace();
}
}
return null;
}
}
我只在日誌貓在得到這Android Studio
日誌貓
11-09 13:08:48.859 675-675/? I/art: Late-enabling -Xcheck:jni
11-09 13:08:48.891 675-691/? I/art: Debugger is no longer active
11-09 13:08:49.286 675-675/? I/LoadedApk: No resource references to update in package common
11-09 13:08:49.287 675-675/? I/LoadedApk: No resource references to update in package com.cyngn.yu
11-09 13:08:49.411 675-755/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-09 13:08:49.417 675-675/? D/Atlas: Validating map...
11-09 13:08:49.459 675-755/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017_msm8916_64_LA.BR.1.1.3_RB1__release_AU (Iac7c2e2837)
11-09 13:08:49.459 675-755/? I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.25.03.04
11-09 13:08:49.459 675-755/? I/Adreno-EGL: Build Date: 06/11/15 Thu
11-09 13:08:49.459 675-755/? I/Adreno-EGL: Local Branch: mybranch10882158
11-09 13:08:49.459 675-755/? I/Adreno-EGL: Remote Branch: quic/LA.BR.1.1.3_rb1.16
11-09 13:08:49.459 675-755/? I/Adreno-EGL: Local Patches: NONE
11-09 13:08:49.459 675-755/? I/Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017 + 26a3cba + 6f69ea6 + 8bc2bc8 + 649fcde + a52cccf + dbf281f + 15f0bf8 + 8d02f76 + 9b2cb1a + 25f3b04 + 7cd8c84 + b54906e + 675fd74 + 7c22ef4 + NOTHING
11-09 13:08:49.460 675-755/? I/OpenGLRenderer: Initialized EGL, version 1.4
11-09 13:08:49.471 675-755/? D/OpenGLRenderer: Enabling debug mode 0
11-09 13:08:49.474 675-755/? I/qdutils: PartialUpdate status: Disabled
11-09 13:08:49.474 675-755/? I/qdutils: Left Align: 0
11-09 13:08:49.474 675-755/? I/qdutils: Width Align: 0
11-09 13:08:49.474 675-755/? I/qdutils: Top Align: 0
11-09 13:08:49.474 675-755/? I/qdutils: Height Align: 0
11-09 13:08:49.474 675-755/? I/qdutils: Min ROI Width: 0
11-09 13:08:49.474 675-755/? I/qdutils: Min ROI Height: 0
11-09 13:08:49.474 675-755/? I/qdutils: Needs ROI Merge: 0
11-09 13:08:49.474 675-755/? I/qdutils: Dynamic Fps: Disabled
11-09 13:08:49.474 675-755/? I/qdutils: Min Panel fps: 0
11-09 13:08:49.474 675-755/? I/qdutils: Max Panel fps: 0
11-09 13:08:49.580 675-675/? I/Timeline: Timeline: Activity_idle id: [email protected] time:12438245
11-09 13:08:49.688 675-675/? I/Timeline: Timeline: Activity_idle id: [email protected] time:12438353
11-09 13:08:53.757 675-675/xyz.tahademure.purplereader W/art: Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
11-09 13:08:54.069 675-976/xyz.tahademure.purplereader V/FetchMangaTask: Built URI https://www.mangaeden.com/api/list/0/?p=1
11-09 13:08:55.951 675-976/xyz.tahademure.purplereader V/FetchMangaTask: Manga Entrynull
要獲得所有的JSON字符串在日誌使用'Log.i( 「TAG」,mangaJsonStr);' –
看起來你在登錄貓獲得更多。 –
發佈完整日誌。 –