tommy_spt

JSON PARSING

May 14th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. private void getData(final String id) {
  2. final ProgressDialog loading = ProgressDialog.show(this, "Memuat Data", "Mohon Tunggu...", false, false);
  3. JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(DATA_URL,
  4. new Response.Listener<JSONArray>() {
  5. @Override
  6. public void onResponse(JSONArray response) {
  7. Log.d(TAG, response.toString());
  8. loading.dismiss();
  9. parseData(response);
  10. }
  11. },
  12. new Response.ErrorListener() {
  13. @Override
  14. public void onErrorResponse(VolleyError error) {
  15. loading.dismiss();
  16.  
  17. }
  18. }) {
  19. protected Map<String, String> getParams() {
  20. Map<String, String> params = new HashMap<String, String>();
  21. params.put("id", id);
  22. return params;
  23. }
  24. };
  25.  
  26. RequestQueue requestQueue = Volley.newRequestQueue(this);
  27. requestQueue.add(jsonArrayRequest);
  28. }
  29.  
  30. private void parseData(JSONArray array) {
  31. for (int i = 0; i < array.length(); i++) {
  32. JSONObject json = null;
  33. try {
  34.  
  35. json = array.getJSONObject(i);
  36. String Judul = json.getString(TAG_JUDUL);
  37. String Gambar = json.getString(TAG_IMAGE);
  38. String Bahan = json.getString(TAG_ISI);
  39. txt_judul.setText(Judul);
  40. txt_bahan.setText(Bahan);
  41.  
  42. } catch (JSONException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment