AsyncHttpResponseHandler未定义发送参数; RequestParams,android,java,php

时间:2016-10-20 07:02:07

标签: java php android post android-asynctask

我有这个代码将数据上传到数据库

RequestParams params = new RequestParams();
//prgDialog.show();
params.put("usersJSON", controller.getAllAnswerSheet());
System.out.println("onSuccess getAllAnswerSheet" + controller.numberOfRows("answer_sheet_tbl"));
System.out.println("onSuccess getAllAnswerSheet" + controller.getAllAnswerSheet());
// Make Http call to updatesyncsts.php with JSON parameter which has Sync statuses of Users
client.post("http://127.0.0.1/qna/process/uploadanswersheet.php", params, new AsyncHttpResponseHandler() {

我知道我有数据,因为我在日志中得到了这个

[{
    "answer": [{
        "sysid": "1",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "1",
        "status": "active"
    }, {
        "sysid": "2",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "2",
        "status": "active"
    }, {
        "sysid": "3",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "3",
        "status": "active"
    }, {
        "sysid": "4",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "4",
        "status": "active"
    }, {
        "sysid": "5",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "5",
        "status": "active"
    }, {
        "sysid": "6",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "6",
        "status": "active"
    }, {
        "sysid": "7",
        "surveyid": "1",
        "questionid": "0",
        "answerid": "",
        "householdid": "7",
        "status": "active"
    }, {
        "sysid": "8",
        "surveyid": "1",
        "questionid": "1",
        "answerid": "aklan",
        "householdid": "8",
        "status": "active"
    }, {
        "sysid": "9",
        "surveyid": "1",
        "questionid": "2",
        "answerid": "kalibo",
        "householdid": "9",
        "status": "active"
    }, {
        "sysid": "10",
        "surveyid": "1",
        "questionid": "3",
        "answerid": "7",
        "householdid": "10",
        "status": "active"
    }, {
        "sysid": "11",
        "surveyid": "1",
        "questionid": "3",
        "answerid": "7",
        "householdid": "11",
        "status": "active"
    }, {
        "sysid": "12",
        "surveyid": "1",
        "questionid": "3",
        "answerid": "7",
        "householdid": "12",
        "status": "active"
    }, {
        "sysid": "13",
        "surveyid": "1",
        "questionid": "6",
        "answerid": "three",
        "householdid": "13",
        "status": "active"
    }, {
        "sysid": "14",
        "surveyid": "1",
        "questionid": "6",
        "answerid": "three",
        "householdid": "14",
        "status": "active"
    }, {
        "sysid": "15",
        "surveyid": "1",
        "questionid": "7",
        "answerid": "patwo",
        "householdid": "15",
        "status": "active"
    }, {
        "sysid": "16",
        "surveyid": "1",
        "questionid": "7",
        "answerid": "pathree",
        "householdid": "16",
        "status": "active"
    }, {
        "sysid": "17",
        "surveyid": "1",
        "questionid": "7",
        "answerid": "pathree",
        "householdid": "17",
        "status": "active"
    }],
    "survey": [{
        "sysid": "17",
        "householdnum": "74",
        "barangay": "manila",
        "headfname": "martin",
        "headmname": "",
        "headlname": "manalo",
        "headsuffix": "",
        "status": "active"
    }]
}]

我的问题出在我的uploadanswersheet.php页面中我得到Undefined index: usersJSON意思是我无法以参数形式发送数据。

这是uploadanswersheet.php中的代码:

//Get JSON posted by Android Application
$json = $_POST["usersJSON"];
//Remove Slashes
$json = json_decode(stripslashes($json), true);
//if (get_magic_quotes_gpc()){
//$json = stripslashes($json);
//}

1 个答案:

答案 0 :(得分:1)

将JSON转换为字符串并发布。并在服务器端将字符串转换回JSON