何度か質問されましたが、問題の解決策が見つかりませんでした。
API: 1を解析しようとしていますが、これは有効な JSON です。
そのために、データを解析する関数を作成しました:
private String[] getArticlesDataFromJson(String allPostsJsonStr, int nbArticlesDisplayed)
throws JSONException {
// These are the names of the JSON objects that need to be extracted.
final String OWM_POSTS = "posts";
final String OWM_ID = "id";
final String OWM_TITLE = "title";
final String OWM_THUMBNAIL = "thumbnail";
JSONObject allContentsPosts = new JSONObject(allPostsJsonStr);
JSONArray contentArticlesArray = allContentsPosts.getJSONArray(OWM_POSTS);
String[] resultStrs = new String[nbArticlesDisplayed];
for (int i = 0; i < contentArticlesArray.length(); i++) {
// For now, using the format "id, title, thumbnail"
int id;
String title;
String thumbnail;
// Get the JSON object representing the article
JSONObject article = contentArticlesArray.getJSONObject(i);
id = article.getInt(OWM_ID);
title = article.getString(OWM_TITLE);
thumbnail = article.getString(OWM_THUMBNAIL);
resultStrs[i] = id + " - " + title + " - " + thumbnail;
}
for (String s : resultStrs) {
Log.v(LOG_TAG, "article : " + s);
}
return resultStrs;
}
AsyncTask では、バッファを使用して Json 文字列 allPostsJsonStr を復元し、結果をアンエスケープして Unicode 文字を回避します。
allPostsJsonStr = StringEscapeUtils.unescapeJava(buffer.toString());
そして、関数を呼び出して結果を解析します。
getArticlesDataFromJson(allPostsJsonStr, 1);
try/catch などで ...
そして、私はエラーを持っています:
{"status":"ok","count":1,"count_total":79,"pages":79,"posts":[{"id":1320,"type" の文字 510 でエラー JSONException 未終了オブジェクト:"post","slug":"vibram-fivefingers-spyridon-mr-ou-comment-allier-legerete-et-plaisir-du-trail","url":" http://leminimaliste.info/vibram- Fivefingers-spyridon-mr-ou-comment-allier-legerete-et-plaisir-du-trail/ ","status":"publish","title":"Vibram FiveFingers Spyridon MR ou comment allier légèreté et plaisir du Trail" ,"title_plain":"Vibram FiveFingers Spyridon MR ou comment allier légèreté et plaisir du Trail","content":"Je souhaite ajourd'hui vous faire un retour sur mon dernier Trail en date avec mes petites nouvelles, les Spyridon MR de VFF.
JSONStringの「コンテンツ」に表示されるhtmlコードにリンクされていることに注意しましたが、このエラーを修正する方法がわかりません。
助けが必要です、ありがとう