Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hey I'm fetching data in Json using array in volley sql, but the error is found that data is not loading in recycler view . I'm fetching all rows which have same id. But data is not loading. here is my code can you tell me where is the error.Please help me to fix it, the data is not loading and in app it is showing json error can not covert string to json array // something like this. help me i'm very close to finish my app

What I have tried:

private void LoadAllJobs() {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, Urls.all_jobs,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONArray jsonArray = new JSONArray(response);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject object = jsonArray.getJSONObject(i);
                            String jobname = object.getString("jobname");
                            String jobdetails = object.getString("jobdetails");
                            String startdate = object.getString("startdate");
                            String enddate = object.getString("enddate");
                            String posts = object.getString("posts");
                            String govtfees = object.getString("govtfees");
                            String appfees = object.getString("appfees");
                            String documents = object.getString("documents");
                            String declartion = object.getString("declartion");


                            AllJobsModel alljobsName = new AllJobsModel(jobname, jobdetails, posts, startdate, enddate, govtfees, appfees, documents, declartion);
                            alljobsName.setJobName(jobname);
                            alljobsName.setJobDetails(jobdetails);
                            allJobs.add(alljobsName);


                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        AndroidUtil.showToast(getApplicationContext(),e.toString());
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }){
        @Nullable
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("id","1");
            return params;
        }

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


    }
PHP
<?php

    require_once "conn.php";
    require_once "validate.php";
    $id = $_POST['id'];
    $sql = "SELECT * from all_jobs WHERE id ='$id'";
    $result=mysqli_query($conn, $sql);
    $all_jobs= array();
    while($row=mysqli_fetch_array($result)){
        
        
        $index['jobname']=$row['jobname'];
        $index['posts']=$row['posts'];
        $index['startdate']=$row['startdate'];
        $index['enddate']=$row['enddate'];
        $index['govtfees']=$row['govtfees'];
        $index['appfees']=$row['appfees'];
        $index['documents']=$row['documents'];
        $index['declartion']=$row['declartion'];
        $index['jobdetails']=$row['jobdetails'];
        

        array_push($all_jobs, $index);
    }
    echo json_encode($all_jobs)
?>    
Posted
Updated 25-Aug-23 1:24am
v2
Comments
Richard MacCutchan 25-Aug-23 3:35am    
"json error can not covert string to json array // something like this."
It would be much simpler, and far more useful, to copy and paste the exact error message.

1 solution

Sorry, but we can't help you - if you read the error message, the problem is with the JSON data not matching the classes it is being deserialised into:
Quote:
json error can not covert string to json array // something like this.
You need to use your IDE debugger to look at exactly what is being processed and what it is being converted into.
And we have no access to either of those.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900