text:
Q: How to get json data from server using Volley i have used volley and get a json data from server. it works well
but when i get a data from server, at android studio log, The data is well received in the form of json. like this
{"read":[{"id":"pp","time":"3","content":"3"},{"id":"pp","time":"22","content":"2"},{"id":"pp","time":"11","content":"1"},{"id":"z","time":"12.12","content":"chest again!"}],"success":"1"}
but i typed server url(when php code exist) at browser and get in there, there is no data from db just shows like
{"read":[],"success":"1"}
here is the java code
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_list, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                System.out.println(response);
                Log.e(TAG, response.toString());

                try {
                    JSONObject jsonObject = new JSONObject(response);
                    String success = jsonObject.getString("success");
                    JSONArray jsonArray = jsonObject.getJSONArray("read");

                    if (success.equals("1")) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject object = jsonArray.getJSONObject(i);
                            String id = object.getString("id").trim();
                            String time = object.getString("time").trim();
                            String content = object.getString("content").trim();

                            adapter.addItem(id, time, content);
                            adapter.notifyDataSetChanged();
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    Toast.makeText(listActivity.this, "Error Reading Detail : " + e.toString(), Toast.LENGTH_SHORT).show();
                }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(listActivity.this, "Error Reading Detail : " + error.toString(), Toast.LENGTH_SHORT).show();
                }
            }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("gymName", gymName);

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

here is the php code on server
<?php
    $con = mysqli_connect("localhost", "db", "pw", "user");
    mysqli_query($con,'SET NAMES utf8');

    $gymName = $_POST["gymName"];

    $sql = "SELECT * FROM test where gymName = '$gymName' ORDER BY num desc";
    $response = mysqli_query($con, $sql);

    $result = array();
    $result['read'] = array();

    while($row = mysqli_fetch_assoc($response)){
        $h['id'] = $row['id'];
        $h['time'] = $row['time'];
        $h['content'] = $row['content'];

        array_push($result['read'], $h);
    }

    $result['success'] = "1";
    echo json_encode($result);
?>

why this happen? plz help
i think in php code, get data from db and implement echo json_encode, should'n be shown db data in URL? i think browser shows json data and android get those shown data Am i wrong?. i just curious how to get a json data from server to android studio


DANNO KLONOWSKI is a cartoonist and podcaster. MATT RISNES is a noted film blogger and podcast guest. They have been, and always shall be, friends for nearly 20 years and like talking about stuff at length and in-depth as they live long and prosper. In the seventeenth episode of the WAYNE GALE VARIETY HOUR Matt, by some miracle brought on by the INTO DARKNESS debacle, has finally watched, embraced, and fallen in love with the original STAR TREK casts' 6 films (something Danno did 27 years ago). That's right listeners: this episode is hard sci-fi TREK TALK!!!
BUT FIRST! We address a Viewer Mail and plug Danno's return to doing the LUTEFISK SUSHI PODCAST in addition to the WGVH cast. Then it's onto One Hitters, including: Matt pushing the DILLINGER ESCAPE PLAN album "One of Us is the Killer", JACK REACHER, the new WOLVERINE and RIDDICK trailers, DARKMAN (and the Sam Raimi Experience), discussing the death of 3D, THE GREAT GATSBY (which Danno endured), THE PROPHETS OF SCIENCE FICTION on Netflix, RIDLEY SCOTT, and finally our insane wanting for MAN OF STEEL to come out RIGHT NOW, DAMMIT!!!
After a musical break by your friend and mine, The SHAT, it's straight into SPOILER-IFFIC talk about STAR TREK INTO DARKNESS (if you want to skip spoilers they run from 52:15 to 1:37:0. That's right! Nearly 45 minutes on INTO DARKNESS, 20 minutes of which are Danno Nerd-Raging and Matt barely getting a word in edge-wise, if you can believe that! Danno also often brings up the Butterfly Effect of JJ Abrams ST universe, but after two Sierra Nevada Torpedos can't pronounce 'butterfly' and just refers to it as a 'Kutchner Effect'. Also during the rest of the ST chat random STID spoilers are just thrown out there without warning. Just FYI.). After that we discuss the Original Casts' first six STAR TREK films and Danno schools Matt a bit on the history of the Trek universe and making of the films. Finally–again by some MIRACLE!!!—thanks to these films Matt has finally embraced the Gene Roddenberry/Carl Sagan dream for all humanity. Kirk Out.
Keep up the good work with the show guys. I am always listening and have been enjoying.


The YHC Management Team works tirelessly behind-the-scenes to keep Chorus operations running smoothly.
From fundraising ideas to organizing educational events, our Management Team is on the job!
We rehearse at the Sharon-Hope United Church in Sharon, ON every Tuesday Nights from 7:00-10:00. Visitors are always welcome, and we encourage you to drop by!