我的應用程序似乎無法運行我的onSuccess方法。AsyncHttpClient JSON onSuccess函數沒有得到執行
它說,在日誌中: 「W/JsonHttpRH:的onSuccess(INT,標題[],JSONArray),其中沒有被重寫,但回調收到」
很多人用它代替的JSONObject JSONArray,但這我的情況並非如此。代碼是:
private void fetchDictionary() {
client = new DictionaryClient();
client.getWords("awesome", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
try {
JSONArray docs = null;
if(response != null) {
// Get the docs json array
docs = response.getJSONArray("docs");
// Parse json array into array of model objects
final ArrayList<Word> words = Word.fromJson(docs);
// Remove all words from the adapter
wordAdapter.clear();
// Load model objects into the adapter
for (Word word : words) {
wordAdapter.add(word); // add word through the adapter
}
wordAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
// Invalid JSON format, show appropriate error.
e.printStackTrace();
}
}
});
}
我使用http://dictionaryapi.net/作爲API。我的網址如下所示:「http://dictionaryapi.net/api/definition/awesome」,它返回一個JSON對象。