8
我認爲我建立的代碼,以獲取從json服務器的數據不是開始。在logcat中沒有來自「log.v」的文本。此外,我所做的代碼似乎並不擅長嘗試捕捉所有的時間。我使用Aquery作爲ajax請求。Aquery ajax請求似乎不開始在android
有其他問題有此問題嗎?
我想把JSON轉換成一個HashMap這樣我就可以建立它的列表視圖,但我不能得到的JSON數據到logcat的
Greathings
public class film_sound extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
View view = inflater.inflate(R.layout.activity_film_sound, container, false);
Context context = inflater.getContext();
String[] Film_Data = getArguments().getStringArray("Film_Data");
File ext = Environment.getExternalStorageDirectory();
File cacheDir = new File(ext, "/android/data/be.moviechecker.programma/case");
AQUtility.setCacheDir(cacheDir);
final AQuery aq = new AQuery(context);
/*Ophalen van de json*/
String url = "http://app.be/data_2_0_0/sound.php?id=1";
aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status) {
if (json != null) {
JSONArray jArray = null;
try {
jArray = json.getJSONArray("soundtrack");
} catch (JSONException e) {
e.printStackTrace();
}
if (jArray.length() == 0) {
Log.v("debug", "dataleeg");
} else {
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = null;
try {
json_data = jArray.getJSONObject(i);
} catch (JSONException e) {
e.printStackTrace();
}
try {
Log.v("debug", json_data.getString("naam"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
} else {
//ajax error, show error code
Log.v("debug", aq.getContext() + "Error:" + status.getCode());
}
}
});
return view;
}
}
看來你使用的是錯誤的網址。嘗試在瀏覽器中打開你的url(複製+粘貼)。沒有json數據返回,只是一個錯誤,該頁面無法找到。在同一時間'AQuery'試圖將返回的數據轉換爲json,這就是爲什麼沒有返回或記錄。嘗試使用正確的URL來獲取json數據。 – rom4ek
它不是真正的URL,我得到狀態200和json從php代碼返回 – user3142817
因此,發佈然後您的**真實的**網址,社區需要重現該問題,所以我們需要所有信息能夠解決你的問題。 – rom4ek