-2

UPDATED JSON FILE IS HERE

  {"posts":[{"post_id":"58","post_desc":"\ud83d\ude0d\ud83d\ude0a","firstname":"karan","lastname":"qq","created_at":"2017-05-30 12:12:36","files":[]},{"post_id":"57","post_desc":"Good Morning","firstname":"karan","lastname":"qq","created_at":"2017-05-30 11:29:43","files":[]},{"post_id":"56","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-26 16:50:49","files":[]},{"post_id":"55","post_desc":"","firstname":"jaxi","lastname":"chawda","created_at":"2017-05-26 16:50:04","files":[]},{"post_id":"54","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-26 16:47:24","files":[{"file_name":"1495797444_IMG_20170522_191006_842.jpg","file_type":"1"}]},{"post_id":"53","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-26 16:45:18","files":[]},{"post_id":"52","post_desc":"","firstname":"jaxi","lastname":"chawda","created_at":"2017-05-26 16:32:24","files":[]},{"post_id":"51","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-26 16:18:31","files":[]},{"post_id":"50","post_desc":"","firstname":"karan","lastname":"qq","created_at":"2017-05-23 17:37:19","files":[{"file_name":"1495541239_VID-20170518-WA0029.mp4","file_type":"2"}]},{"post_id":"49","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-16 16:19:13","files":[{"file_name":"1494931753_IMG_3919.mp4","file_type":"2"}]},{"post_id":"48","post_desc":"","firstname":"jaxi","lastname":"chawda","created_at":"2017-05-16 15:09:32","files":[{"file_name":"1494927572_Technology in the Future.mp4","file_type":"2"}]},{"post_id":"47","post_desc":"","firstname":"pankti","lastname":"shah","created_at":"2017-05-16 13:30:09","files":[{"file_name":"1494921609_Tom and Jerry - Little School Mouse.mp4","file_type":"2"}]},{"post_id":"46","post_desc":"","firstname":"pankti","lastname":"shah","created_at":"2017-05-16 13:16:34","files":[{"file_name":"1494920794_Tubelight _ Official Teaser _ Salman Khan _ Kabir Khan.mp4","file_type":"2"}]},{"post_id":"45","post_desc":"","firstname":"pankti","lastname":"shah","created_at":"2017-05-16 13:13:51","files":[{"file_name":"1494920631_small.mp4","file_type":"2"}]},{"post_id":"44","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-13 16:45:08","files":[{"file_name":"1494674108_IMG_4126.JPG","file_type":"1"}]},{"post_id":"43","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-13 16:24:30","files":[{"file_name":"1494672870_IMG_4123.JPG","file_type":"1"}]},{"post_id":"42","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-13 16:23:25","files":[{"file_name":"1494672805_IMG_4124.JPG","file_type":"1"}]},{"post_id":"41","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-13 15:48:39","files":[{"file_name":"1494670719_IMG_4121.JPG","file_type":"1"}]},{"post_id":"40","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 22:53:24","files":[{"file_name":"1494609804_IMG_4119.JPG","file_type":"1"}]},{"post_id":"39","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 18:28:28","files":[{"file_name":"1494593908_IMG_4015.JPG","file_type":"1"}]},{"post_id":"38","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 14:13:20","files":[{"file_name":"1494578600_IMG_4113.PNG","file_type":"1"}]},{"post_id":"37","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 14:13:18","files":[{"file_name":"1494578598_IMG_4113.PNG","file_type":"1"}]},{"post_id":"36","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 14:13:15","files":[{"file_name":"1494578595_IMG_4113.PNG","file_type":"1"}]},{"post_id":"35","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 14:13:12","files":[{"file_name":"1494578592_IMG_4113.PNG","file_type":"1"}]},{"post_id":"34","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-12 14:13:09","files":[{"file_name":"1494578589_IMG_4113.PNG","file_type":"1"}]},{"post_id":"33","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:43:42","files":[{"file_name":"1494526422_IMG_3950.JPG","file_type":"1"}]},{"post_id":"32","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:43:10","files":[{"file_name":"1494526390_IMG_3944.JPG","file_type":"1"}]},{"post_id":"31","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:26:24","files":[{"file_name":"1494525384_IMG_3127.JPG","file_type":"1"}]},{"post_id":"30","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:26:20","files":[{"file_name":"1494525380_IMG_3127.JPG","file_type":"1"}]},{"post_id":"29","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:24:12","files":[{"file_name":"1494525252_IMG_2600.JPG","file_type":"1"}]},{"post_id":"28","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:24:06","files":[{"file_name":"1494525246_IMG_2600.JPG","file_type":"1"}]},{"post_id":"27","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:22:04","files":[{"file_name":"1494525124_IMG_3113.JPG","file_type":"1"}]},{"post_id":"26","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:21:11","files":[{"file_name":"1494525071_1491304854804.jpeg","file_type":"1"}]},{"post_id":"25","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:20:26","files":[{"file_name":"1494525026_IMG_4050.JPG","file_type":"1"}]},{"post_id":"24","post_desc":"Ganesh Mahotsav 2016 ","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:20:01","files":[{"file_name":"1494525001_IMG_4045.PNG","file_type":"1"}]},{"post_id":"23","post_desc":"","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-11 23:19:03","files":[{"file_name":"1494524943_IMG_4016.JPG","file_type":"1"}]},{"post_id":"22","post_desc":"\ud83d\ude0d\n","firstname":"karan","lastname":"qq","created_at":"2017-05-10 14:57:16","files":[]},{"post_id":"21","post_desc":"\ud83d\ude0a\n","firstname":"karan","lastname":"qq","created_at":"2017-05-04 11:06:07","files":[]},{"post_id":"20","post_desc":"\ud83d\ude0a\n","firstname":"karan","lastname":"qq","created_at":"2017-05-04 11:06:03","files":[]},{"post_id":"19","post_desc":"Good morning","firstname":"karan","lastname":"qq","created_at":"2017-05-04 11:05:27","files":[]},{"post_id":"18","post_desc":"https:\/\/www.youtube.com\/watch?v=Qtp42J9IOUo","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:39:53","files":[]},{"post_id":"17","post_desc":"\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c\ud83d\ude1c","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:38:40","files":[]},{"post_id":"16","post_desc":"hi hello","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:30:35","files":[]},{"post_id":"15","post_desc":"\ud83d\ude0e\ud83d\ude34\ud83d\ude01","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:30:19","files":[]},{"post_id":"14","post_desc":"\ud83d\ude0e\ud83d\ude34\ud83d\ude01","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:30:17","files":[]},{"post_id":"13","post_desc":"\ud83d\ude0e\ud83d\ude34\ud83d\ude01","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:30:17","files":[]},{"post_id":"12","post_desc":"\ud83d\ude0e\ud83d\ude34\ud83d\ude01","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:30:16","files":[]},{"post_id":"11","post_desc":"\ud83d\ude0e\ud83d\ude34\ud83d\ude01","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:30:16","files":[]},{"post_id":"10","post_desc":"\ud83d\ude0a\ud83d\ude0a\ud83d\ude04\ud83d\ude04\u263a\ufe0f\ud83d\ude01\ud83d\ude01","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:30:14","files":[]},{"post_id":"9","post_desc":"Going to receive loads of money....","firstname":"Manish","lastname":"Amin","created_at":"2017-05-02 16:08:58","files":[]},{"post_id":"8","post_desc":"\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:08:57","files":[]},{"post_id":"7","post_desc":"\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:08:55","files":[]},{"post_id":"6","post_desc":"\ud83d\ude02\ud83d\ude02\ud83d\ude02\ud83d\ude02","firstname":"Abc","lastname":"Xyz","created_at":"2017-05-02 16:08:47","files":[]},{"post_id":"5","post_desc":"\ud83c\udfe1\ud83c\udfeb","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:05:40","files":[]},{"post_id":"4","post_desc":"\ud83d\udc4d\ud83d\udc4d\ud83d\ude0a\ud83d\ude12\ud83d\udc2e\ud83d\ude48\ud83d\ude1c\ud83d\ude09\ud83d\ude03","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 16:02:21","files":[]},{"post_id":"3","post_desc":"\ud83d\ude12\ud83d\ude0a","firstname":"Rushin","lastname":"Patel","created_at":"2017-05-02 15:58:42","files":[]},{"post_id":"2","post_desc":"\ud83d\ude33\ud83d\ude33\ud83d\ude33","firstname":"jaxi","lastname":"chawda","created_at":"2017-05-02 15:57:31","files":[]},{"post_id":"1","post_desc":"hii....good afternoon...\ud83d\ude04\ud83d\ude04\ud83d\ude04","firstname":"jaxi","lastname":"chawda","created_at":"2017-05-02 15:55:49","files":[]}]}

ANDROID CODE IS HERE I UPDATED BT IMAGEs ARE REPEATING WITH DIFFERENT USERS IN ANDROID APP PLEASE HELP TO SOLVE THIS SILLY ERROR!!

   public class Sample extends AppCompatActivity {
    private static final String URL_DATA = "www.sample.com/home_webservice.php";
    LinearLayout linearLayout;
    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;

    private List<Data_SAerver> data_sAervers;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recyclerview);
        linearLayout = (LinearLayout) findViewById(R.id.linaralayout1);

        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Sample.this, Posts_DATA.class);
                startActivity(i);
            }
        });
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        data_sAervers = new ArrayList<>();

        loadRecyclerViewData();

    }

    private void loadRecyclerViewData() {
        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("Loading...");
        progressDialog.show();


        StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_DATA,

                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        progressDialog.dismiss();

                        String filename = "";
                        String filetype = "";

                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            JSONArray posts = jsonObject.getJSONArray("posts");
                            if (posts != null && posts.length() > 0) {
                                for (int i = 0; i < posts.length(); i++) {
                                    JSONObject fileObj = posts.getJSONObject(i);

                                    String fName = fileObj.getString("firstname");
                                    String created_at = fileObj.getString("created_at");
                                    String post_desc = fileObj.getString("post_desc");


                                    Log.e("Details", fName + "" + created_at + "" + post_desc);

                                    JSONArray files = fileObj.getJSONArray("files");
                                    if (files != null && files.length() > 0) {


                                        for (int j = 0; j < files.length(); j++) {
                                            JSONObject Jsonfilename = files.getJSONObject(j);
                                            filename = Jsonfilename.getString("file_name");
                                            filetype = Jsonfilename.getString("file_type");


                                            filename = "http://uat.ziplife.in/img/Post/compress/" + filename;
                                            //filename = "http://uat.ziplife.in/img/Post/" + filename;

                                            Log.e("Files", "" + filename);
                                        }


                                    } else

                                    {
                                        filename = "";
                                        filetype = "";
                                    }

                                    Data_SAerver item = new Data_SAerver(fName, created_at, post_desc, filename, filetype);
                                    data_sAervers.add(item);
                                }
                            }

                            adapter = new MyAdapter(data_sAervers, getApplicationContext());

                            recyclerView.setAdapter(adapter);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressDialog.dismiss();

                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();

            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }
}

Here only I got "posts" data. Please help me to get "files" data.

Thank You

7 Answers7

4

try this working fine

try {
    JSONObject jsonObject = new JSONObject(s);

    JSONArray posts = jsonObject.getJSONArray("posts");

    if(posts != null && posts.length() > 0 ) {

        for (int i = 0; i < posts.length(); i++) {

            JSONObject fileObj = posts.getJSONObject(i);

            String fName = fileObj.getString("firstname");
            String created_at = fileObj.getString("created_at");
            String post_desc =  fileObj.getString("post_desc");

            Log.e("Details",fName+""+created_at+""+post_desc);

            JSONArray files = fileObj.getJSONArray("files");
            if(files != null && files.length() > 0 ) {
                for(int j=0 ; j<files.length() ; j++)
                {
                    JSONObject Jsonfilename = files.getJSONObject(j);
                    String filename = Jsonfilename.getString("file_name");

                    Log.e("Files",""+filename);
                }
            }

        }
    }
} catch (JSONException e) {
    e.printStackTrace();
}
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

FYI

Check JSONArray element files is empty or not .

You need to create for loop with respect to JSONArray .

.........Above old code......... 
JSONObject fileObj = posts.getJSONObject(i);
JSONArray arr = fileObj.getJSONArray("files");

if(arr.length()>0)
{
    for(int k=0;k< arr.length(); k++)

    {
     JSONObject J_OBJ= arr.getJSONObject(k);
     String str_FILE=J_OBJ.getString("firstname");

    }
}
else
{
   // Array is Empty 
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0
String filename = "";
        try {
            JSONObject jsonObject = new JSONObject(s);
            JSONArray posts = jsonObject.getJSONArray("posts");
            if(posts != null && posts.length() > 0 ) {
                for (int i = 0; i < posts.length(); i++) {
                    JSONObject fileObj = posts.getJSONObject(i);

                    String fName = fileObj.getString("firstname");
                    String created_at = fileObj.getString("created_at");
                    String post_desc = fileObj.getString("post_desc");


                    Log.e("Details", fName + "" + created_at + "" + post_desc);

                    JSONArray files = fileObj.getJSONArray("files");
                    if(files != null && files.length() > 0 ) {

                        for (int j = 0; j < files.length(); j++) {
                            JSONObject Jsonfilename = files.getJSONObject(j);
                            filename = Jsonfilename.getString("file_name");

                            Log.e("Files", "" + filename);
                        }
                    }

                    Data_SAerver item = new Data_SAerver(fName,created_at,post_desc,filename);
                    data_sAervers.add(item);
                }
            }

        }catch (Exception e)
        {
            Log.e("Error",""+e);
        }
Janak
  • 607
  • 5
  • 23
0

Getting the "files" JSONArray is just like what you have have done with the "post" JSONArray. You need to create a List field in Data_SAerver class to hold your filenames.

See the inline comments for details.

try {
    JSONObject jsonObject = new JSONObject(s);

    JSONArray posts = jsonObject.getJSONArray("posts");

    for (int i = 0; i < posts.length(); i++) {
        JSONObject fileObj = posts.getJSONObject(i);

        Data_SAerver item = new Data_SAerver(
                fileObj.getString("firstname"),
                fileObj.getString("created_at"),
                fileObj.getString("post_desc"));

        // Get files array
        JSONArray files = fileObj.getJSONArray("files");
        // Create a List for storing the filenames
        List<String> fileNameArray = new ArrayList<>();

        // Iterate the files array
        for (int j = 0; j < files.length(); j++) {
            JSONObject fileNameObj = files.getJSONObject(i);

            // Get file_name string
            String fileName = fileNameObj.getString("file_name");

            // Add the filename to the filename array
            fileNameArray.add(fileName);
        }

        // Store it in the model object. You will need to create this field in Data_SAerver class
        item.setFileNames(fileNameArray);

        data_sAervers.add(item);
    }
} catch (JSONException e) {
    e.printStackTrace();
}
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
0
try {
            JSONObject jsonObject = new JSONObject(response);
            JSONArray posts = jsonObject.getJSONArray("posts");
            for(int i=0 ; i<posts.length() ; i++) {
                JSONObject fileObj = posts.getJSONObject(i);
                String fName = fileObj.getString("firstname");
                String created_at = fileObj.getString("created_at");
                String post_desc =  fileObj.getString("post_desc");

                Log.e("Details",fName+""+created_at+""+post_desc);

                JSONArray files = fileObj.getJSONArray("files");
                if(!files.isEmpry()){
                    for(int j=0 ; j<files.length() ; j++)
                    {
                        JSONObject Jsonfilename = files.getJSONObject(j);
                        String filename = Jsonfilename.getString("file_name");
                    }    
                    }else{
                            //what you want to do
                 }

            }

        }catch (Exception e)
        {
            Log.e("Error",""+e);
        }
ND1010_
  • 3,743
  • 24
  • 41
0

FULL CODE IS HERE

public class Sample extends AppCompatActivity  {
private static final String URL_DATA = "http://uat.ziplife.in/mobileapp/home_post_service.php";

private RecyclerView recyclerView;
    private  RecyclerView.Adapter adapter;

    private List<Data_SAerver>data_sAervers;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recyclerview);

recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
     recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        data_sAervers = new ArrayList<>();

        loadRecyclerViewData();

    }

private void loadRecyclerViewData(){
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Loading....");
    progressDialog.show();


    StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_DATA,

            new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            progressDialog.dismiss();


            String filename = "http://uat.ziplife.in/img/Post/compress/";
            try {
                JSONObject jsonObject = new JSONObject(s);
                JSONArray posts = jsonObject.getJSONArray("posts");
                if(posts != null && posts.length() > 0 ) {
                    for (int i = 0; i < posts.length(); i++) {
                        JSONObject fileObj = posts.getJSONObject(i);

                        String fName = fileObj.getString("firstname");
                        String created_at = fileObj.getString("created_at");
                        String post_desc = fileObj.getString("post_desc");


                        Log.e("Details", fName + "" + created_at + "" + post_desc);

                        JSONArray files = fileObj.getJSONArray("files");
                        if(files != null && files.length() > 0 ) {

                            for (int j = 0; j < files.length(); j++) {
                                JSONObject Jsonfilename = files.getJSONObject(j);
                                filename = Jsonfilename.getString("file_name");
                                filename = "http://uat.ziplife.in/img/Post/compress/"+filename;
                                Log.e("Files", "" + filename);
                            }
                        }

                        Data_SAerver item = new Data_SAerver(fName,created_at,post_desc,filename);
                        data_sAervers.add(item);
                    }
                }

          adapter = new MyAdapter(data_sAervers,getApplicationContext());

                recyclerView.setAdapter(adapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            progressDialog.dismiss();

            Toast.makeText(getApplicationContext(), error.getMessage(),Toast.LENGTH_LONG).show();

        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

        }

DATA_SEVER CLASS CODE

public class Data_SAerver {

private String firstname;
private  String created_at;
private  String post_desc;





    public Data_SAerver(String firstname, String created_at, String post_desc) {
        this.firstname = firstname;
        this.created_at = created_at;
        this.post_desc = post_desc;

    }


    public String getFirstname() {
        return firstname;
    }

    public String getCreated_at() {
        return created_at;
    }

    public String getPost_desc() {
        return post_desc;
    }


}

MY ADAPTER CLASS CODE

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private List<Data_SAerver> data_sAervers;

    private Context context;
    public MyAdapter(List<Data_SAerver> data_sAervers, Context context) {
        this.data_sAervers = data_sAervers;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sample, parent, false);
        return new ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        Data_SAerver data_sAerver = data_sAervers.get(position);
        holder.firstname.setText(data_sAerver.getFirstname());
      holder.created_at.setText(data_sAerver.getCreated_at());
        holder.post_desc.setText(data_sAerver.getPost_desc());




            Picasso.with(context).load(data_sAerver.getFiles()).into(holder.files);
   }


    @Override
    public int getItemCount() {
        return data_sAervers.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{

        public TextView firstname;
        public TextView created_at;
        public  TextView post_desc;
public ImageView files;

        public ViewHolder(View itemView) {
            super(itemView);

            firstname = (TextView) itemView.findViewById(R.id.firstname);
            created_at = (TextView) itemView.findViewById(R.id.created_at);
            post_desc= (TextView)itemView.findViewById(R.id.post_desc);
            files = (ImageView)itemView.findViewById(R.id.files);


        }
    }

}
  • where is Data_SAerver Class code? – Janak May 30 '17 at 11:33
  • public class Data_SAerver { private String firstname; private String created_at; private String post_desc; public Data_SAerver(String firstname, String created_at, String post_desc) { this.firstname = firstname; this.created_at = created_at; this.post_desc = post_desc; } public String getFirstname() { return firstname; } public String getCreated_at() { return created_at; } public String getPost_desc() { return post_desc; } } – karan brahmaxatriya May 30 '17 at 11:35
  • Check my Updated Answers. – Janak May 30 '17 at 11:46
  • CODE I UPDATED @Janak – karan brahmaxatriya May 30 '17 at 13:05
0
 try {
        JSONObject jsonObject = new JSONObject(s);
        JSONArray posts = jsonObject.getJSONArray("posts");
        for(int i=0 ; i<posts.length() ; i++) {
            JSONObject fileObj = posts.getJSONObject(i);
            JSONArray files = fileObj.getJSONArray("files");
            for(int j=0 ; j<files.length() ; j++)
           {  
                Log.e("Files",""+files.get(j)+" "+fileObj.getString("firstname")+" "+ fileObj.getString("created_at")+" "+fileObj.getString("post_desc"));
            }
        }

    }catch (Exception e)
    {
        e.printStackTrace();
    }
Trupti Nasit
  • 177
  • 2
  • 15