dongweihuan8610 2019-08-02 09:07
浏览 214

为什么我得到这个错误值成功的java.lang.string类型无法转换为JSONOBJECT?

I am developing this android app which I send the data on server and then I have to retrieve the data and show them on a chart (anychartLibrary).

I've written this php code which helps me send the date to the server and retrieve the data related to that date, but instead of getting a jsonObject I get this html line, which I have noticed using Postman...

<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {

    require_once('init.php');

    $myDate =$_GET['myDate'];

    $sql =" SELECT * FROM parkinsonism_value WHERE myDate='$myDate' ;";
    $result = mysqli_query($connect,$sql);

    $row = mysqli_fetch_assoc($result);

    if (isset($row)) {       
        $record['myDate'] = $row['myDate'];
        $record['parkinsonism'] = $row['parkinsonism'];            
    } else {
        $record['myDate'] ="";
        $record['parkinsonism'] ="";
    }

    header('Content-type=application/json');
    echo json_encode(array("list"=>$record),JSON_UNESCAPED_SLASHES);      
}
?>

and this is the volley json Object Request:

public void getString(){
    String url = "http://46.4.151.237/StHans/getparkinsonism.php"+"?myDate="+finalDate;

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {

    @Override
    public void onResponse(JSONObject response) {

        Toast.makeText(getContext(),response.toString(),Toast.LENGTH_SHORT).show();
            try {
                 jsObject =response.getJSONObject("list");
                 sss =jsObject.getString("parkinsonism");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getContext(),error.getMessage(),Toast.LENGTH_SHORT).show();
        }
    });

    // Access the RequestQueue through your singleton class.
    MySingleton.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
}

by the way about the final date:

calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

finalDate =dayOfMonth +"/"+(month +1)+"/"+ year;

now I have this error which tells me value success of type java.lang.string cannot be converted to JSONOBJECT. what should I change to get this to work? thanks:|

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么