-1

I want get JSON from URL address, this simple JSON in URL

 [
  {
    "id": "1",
    "name": "دانیال",
    "sex": "male",
    "reshte": "تجربی",
    "rotbe": "3000+",
    "image": "https://xxxxxx.png",
    "telegram": "danyall1377",
    "instagram": "danyall1377",
    "phone": "09xxxxxxxxx"
  },
  {
    "id": "2",
    "name": "دانیال",
    "sex": "male",
    "reshte": "تجربی",
    "rotbe": "3000+",
    "image": "xxxxxxxxx.png",
    "telegram": "dadddddd",
    "instagram": "ddddddd",
    "phone": "091xxxxxxx"
  }
]

Is there easy way for do that?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Simko
  • 45
  • 8

2 Answers2

1

You can use third party libraries like volley, retrofit.... for example with volley you should make a JsonArrayRequest to the server and parse it.

Farsi resource

English resource

and this is a basic request:

JsonArrayRequest jarr = new JsonArrayRequest(Request.Method.GET, URL, null, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {

            try{

                for(int i=0;i<response.length();i++){
                    JSONObject job = response.getJSONObject(i);
                    String name = job.getString("name");

                }

            } catch (Exception e){


            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {


        }
    });

    requestQueue.add(jarr);
Hesam Rasoulian
  • 1,356
  • 3
  • 12
  • 18
-1

For getting data from server using retrofit library: https://square.github.io/retrofit/

Retrofit good example: https://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/

For directly making classes of JSON reponse use: http://www.jsonschema2pojo.org/

Erselan Khan
  • 692
  • 6
  • 13
  • 3
    Please don't copy-paste the links here. instead, try to demonstrate how answer should be.(Preferably in code) [**How do I write a good answer?**](https://stackoverflow.com/help/how-to-answer) – ʍѳђઽ૯ท Aug 19 '18 at 08:23