WCF servisime Volley üzerinden bir GET isteği yapmaya çalışıyorum ve bir Java ArrayList
cevabını ayrıştırmak istiyorum. Ben JSON yanıtını ancak ArrayList<Company>
döner boş almak mümkünAndroid Parse Json Java ArrayList'e Yanıt
{"GetCompaniesResult":[{"CompanyId":1,"CompanyName":"CompanyName1"},{"CompanyId":2,"CompanyName":"CompanyName2"}]}
: İşte benim yöntem
public ArrayList<Company> getCompanies(){
String url = AUDITTRACKINGAPP_SERVICE_URI + "GetCompanies";
String tagJsonReq = "companiesRequest";
final ProgressDialog pDialog = new ProgressDialog(context);
pDialog.setMessage("Please Wait...");
pDialog.show();
final ArrayList<Company> companies = new ArrayList<Company>();
JsonObjectRequest companiesRequest = new JsonObjectRequest( Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.v(TAG, "COMPANIES RESPONSE:" + response.toString());
try {
JSONArray companiesJson = response.getJSONArray("GetCompaniesResult");
for (int i = 0; i < companiesJson.length(); i++) {
JSONObject jObject = (JSONObject)companiesJson.get(i);
Company company = new Company();
company.setCompanyId(Integer.parseInt(jObject.getString("CompanyId")));
Log.v(TAG, "COMPANIES setCompanyId:" + jObject.getString("CompanyId"));
company.setCompanyName(jObject.getString("CompanyName"));
Log.v(TAG, "COMPANIES setCompanyName:" + jObject.getString("CompanyName"));
companies.add(company);
}
} catch (JSONException e) {
Log.v(TAG, "COMPANIES RESPONSE ERROR ON PARSING JSON:" + e.getMessage());
}
pDialog.hide();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.v(TAG, "COMPANIES onErrorResponse:" + error.getMessage());
pDialog.hide();
}
});
AppController.getInstance().addToRequestQueue(companiesRequest, tagJsonReq);
return companies;
}
JSON TEPKİ olduğunu. Ben
onResponse
bir calback yöntemi olduğunu düşünüyorum ve başka bir iş parçacığı içinde çalışır bu yüzden listeyi doldurmak değil ama ben bir Android acemi olduğum için bu sorunu nasıl yönetileceğini bilmiyorum. Herhangi bir yardım takdir edilecektir.
Günlükte çıktı alıyor musunuz? –
Evet, JSON yanıtı @AiyazParmar – Tartar
'un başarıyla yürütme döngüsünü gördüğümü görüyorum? –