Reputation: 181
I'm using Volley and looking at this ( http://www.androidhive.info/2014/09/android-json-parsing-using-volley/ ) tutorial, but I don't know how to make it work. Using ObjectJSON, error says "it can't be converted to Array" and if I use ArrayJSON method it doesn't found database elements. My urlJSON - http://smkbaig.esy.es/get_info_test.php
Upvotes: 0
Views: 50
Reputation: 1160
Your JSON following the php link you provided starts with { and as the tutorial said, that's a JSON Object, followed by an array called "receptai".
If you have followed the tutorial correctly till the end, it should work using makeJsonArrayRequest()
You really need to paste your code here so that we could help further.
What you might want to do first is follow the tutorial exactly the way it was presented, and if you get responses successfully, then start experimenting and changing. I see you are using your own JSON instead of coding for both JsonArrays and JsonObjects and seeing both buttons get functional.
Upvotes: 1
Reputation: 181
Thnaks @iBobb for answer, it helped me. Here is how it worked out:
try {
JSONArray ja = response.getJSONArray("receptai");
for (int i = 0; i < ja.length(); i++) {
JSONObject jsonObject = ja.getJSONObject(i);
rec = new Receptas();
rec.setPav(jsonObject.getString("pav"));
rec.setApras(jsonObject.getString("apras"));
rec.setIngred_sk(jsonObject.getString("ingred_sk"));
recList.add(rec);
}
// ListView
// txtResponse.setText(data);
} catch (JSONException e) {
e.printStackTrace();
}
Upvotes: 0