Получить строковые данные Json - PullRequest
0 голосов
/ 30 мая 2020

Я новичок ie в Json. Я не понимаю, как разобрать этот Json. Я использую залп и получаю данные в recyclerview. Помогите мне получить эти данные.

Это json lookin:


    [{
        "id":"ahiru-no-sora-dub-episode-1"
        },{
        "id":"ahiru-no-sora-dub-episode-2"
        },{
            "id":"ahiru-no-sora-dub-episode-3"
            },{"id":"ahiru-no-sora-dub-episode-4"
            },{"id":"ahiru-no-sora-dub-episode-5"
            },{"id":"ahiru-no-sora-dub-episode-6"
            },{"id":"ahiru-no-sora-dub-episode-7"
            },{"id":"ahiru-no-sora-dub-episode-8"
            },{"id":"ahiru-no-sora-dub-episode-9"
            },{"id":"ahiru-no-sora-dub-episode-10"
            },{"id":"ahiru-no-sora-dub-episode-11"
            },{"id":"ahiru-no-sora-dub-episode-12"
            },{"id":"ahiru-no-sora-dub-episode-13"
            },{"id":"ahiru-no-sora-dub-episode-14"
            },{"id":"ahiru-no-sora-dub-episode-15"
            },{"id":"ahiru-no-sora-dub-episode-16"
            },{"id":"ahiru-no-sora-dub-episode-17"
            },{"id":"ahiru-no-sora-dub-episode-18"
            },{"id":"ahiru-no-sora-dub-episode-19"
            },{"id":"ahiru-no-sora-dub-episode-20"}]


Это метод, который я вызываю из Activity:

public class OnGoingDetails extends AppCompatActivity
{
    private RecyclerView mRecyclerView;
    private EpisodeListAdapter mExampleAdapter;
    private ArrayList<EpisodeListModel> mExampleList;
    private RequestQueue mRequestQueue;
    private ProgressDialog loadingPop;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ongoing_detail);


mRecyclerView = findViewById(R.id.recycler_view);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mExampleList = new ArrayList<>();
        mRequestQueue = Volley.newRequestQueue(this);

        loadingPop = new ProgressDialog(this);
        loadingPop.setTitle("Loading...");
        loadingPop.setMessage("Please wait retrieving data from server");
        loadingPop.setCanceledOnTouchOutside(false);
        loadingPop.show();


    Bundle extra = getIntent().getExtras();
    String url = extra.getString("ID");
    //Toast.makeText(OnGoingDetails.this,url, Toast.LENGTH_SHORT).show();
    JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null,
        new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response)
        {
            try
            { 
            Toast.makeText(OnGoingDetails.this,s, Toast.LENGTH_SHORT).show();
            JSONObject jsonob = new JSONObject();
            JSONObject jo;
            for(int i=0;i<jsonArray.length();i++){
                jo=jsonArray.getJSONObject(i);
                String ids=jo.getString("id");
               loadingPop.dismiss();
                Toast.makeText(OnGoingDetails.this, "Data: "+ids, Toast.LENGTH_SHORT).show();
                ClipboardManager clipboard = (ClipboardManager) OnGoingDetails.this.getSystemService(Context.CLIPBOARD_SERVICE); 
                ClipData clip = ClipData.newPlainText("label","data"+ids); //ids.toString());
                clipboard.setPrimaryClip(clip);

                //Toast.makeText(getActivity(), "Data Refreshed", Toast.LENGTH_SHORT).show();
                mExampleList.add(new EpisodeListModel(ids));
                loadingPop.dismiss();
                }
                mExampleAdapter = new EpisodeListAdapter(OnGoingDetails.this, mExampleList);
                mRecyclerView.setAdapter(mExampleAdapter);
                //Toast.makeText(getActivity(), "Added Data", Toast.LENGTH_SHORT).show();
                loadingPop.dismiss();

            }
            catch (JSONException e)
            {
                e.printStackTrace();
                Toast.makeText(OnGoingDetails.this, "Catch" + e, Toast.LENGTH_LONG).show();
                loadingPop.dismiss();

            }}
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            if (error instanceof NetworkError)
            {
            loadingPop.dismiss();
            Toast.makeText(OnGoingDetails.this,
                       "Oops. Network error!",
                       Toast.LENGTH_LONG).show();
            }
            else if (error instanceof ServerError)
            {
            loadingPop.dismiss();
            Toast.makeText(OnGoingDetails.this,
                       "Oops. Server error!",
                       Toast.LENGTH_LONG).show();
            }
            else if (error instanceof AuthFailureError)
            {
            loadingPop.dismiss();
            Toast.makeText(OnGoingDetails.this,
                       "Oops. Authintication error!",
                       Toast.LENGTH_LONG).show();
            }
            else if (error instanceof ParseError)
            {
            loadingPop.dismiss();
            Toast.makeText(OnGoingDetails.this,
                       "Oops. Parse error!",
                       Toast.LENGTH_LONG).show();
            }
            else if (error instanceof NoConnectionError)
            {
            loadingPop.dismiss();
            Toast.makeText(OnGoingDetails.this,
                       "No Internet Connection!",
                       Toast.LENGTH_LONG).show();
            }
            else if (error instanceof TimeoutError)
            {
            Toast.makeText(OnGoingDetails.this,
                       "Oops. Timeout error!",
                       Toast.LENGTH_LONG).show();
            loadingPop.dismiss();
            }
        }
        }
    );
        request.setRetryPolicy(new DefaultRetryPolicy(
                       10000,
                       DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        mRequestQueue.add(request);

        }
        }

* Примечание: я использую Volley Online api и получаю этот json из другого действия с использованием Intent (Bundle) *

...