AsyncHttpResponseHandler 未定义发送参数;RequestParams,android,java,php
Posted
技术标签:
【中文标题】AsyncHttpResponseHandler 未定义发送参数;RequestParams,android,java,php【英文标题】:AsyncHttpResponseHandler getting undefined for send params ;RequestParams, android, java, php 【发布时间】:2017-03-02 01:09:24 【问题描述】:我有这段代码可以将数据上传到数据库
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);
//
【问题讨论】:
请检查 usersJSON 是否正在使用 isset if(isset($_POST['usersJSON'])) echo "true"; else 回声“假”; "AsyncHttpResponseHandler getting undefined for send params RequestParams android java php" - 这是一句话吗?还是只是单词的集合? @JagadeshaNH 它没有被发布,因为错误显示未定义。我只是尝试发送一个文本和 php 得到它。不允许在参数中发送 JSONArray 吗?我必须将其转换为字符串然后在 php 中再次转换吗? @BrownmanRevival 是的,您需要将其转换为字符串,为什么不使用 Apache HTTP 客户端。 因为这种方式是我在搜索解决方案时遇到的第一个方式,所以当我将其转换为字符串时,我会尝试使用 Apache HTTP,它可以工作,您可以提供它作为答案,我会尽快接受 @JagadeshaNH 【参考方案1】:将 JSON 转换为字符串并发布。并在服务器端将字符串转换回 JSON
【讨论】:
以上是关于AsyncHttpResponseHandler 未定义发送参数;RequestParams,android,java,php的主要内容,如果未能解决你的问题,请参考以下文章