我收到此錯誤
錯誤:數組字符串轉換在路徑上線37Json在解析php時插入錯誤?
<?php
include('config.php');
// read json file
if($_SERVER['REQUEST_METHOD'] == "GET"){
$filename = 'employee.json';
$json_data = file_get_contents($filename);
// $json_data=$_POST['QUESTION'];
//convert json object to php associative array
$data = json_decode($json_data,true);
if (is_array($data) || is_object($data))
{
for($j=0;$j<sizeof($data);$j++){
//$jsonData[$j] = $data[$j]['DATA'];
//$jsonAnswers[$j] = $data[$j]['ANSWERS'];
$drmobile = $data[$j]['DATA']['DRMOBILE'];
$divcode = $data[$j]['DATA']['DIVCODE'];
$brdcode = $data[$j]['DATA']['BRDCODE'];
$prdcode = $data[$j]['DATA']['PRDCODE'];
$createdon = $data[$j]['DATA']['CREATEDON'];
// echo $drmobile." -- ";
for($i=0;$i<sizeof($data[$j]['ANSWERS']);$i++)
{
$quecode[$i] = $data[$j]['ANSWERS'][$i]['ADCODE'];
$answer[$i] = $data[$j]['ANSWERS'][$i]['ANSWER'];
// $quecodes=$quecode[$i];
// $answers=$answer[$i];
echo $quecode[$i]." <--> ".$answer[$i]."<br/>";
}
echo "<br/>-----------<br/>";
$sql="INSERT INTO U_ANSWERS(DRMOBILE,ADCODE,DIVCODE,BRDCODE,PRDCODE,ANSWERS,CREATEDON)
VALUES ('$drmobile', '$quecode', '$divcode', '$brdcode', '$prdcode', '$answer', '$createdon');";
$qur = mysql_query($sql);
if($qur){
$json = array("status" => 1, "msg" => "Done User added!");
}else{
$json = array("status" => 2, "msg" => "Already Submitted");
}
}
}
}else{
$json = array("status" => 0, "msg" => "Request method not accepted");
}
@mysql_close($conn);
/* Output header */
// header('Content-type: application/json');
echo json_encode($json);
//close connection
?>
樣品的Json
[{
"DATA": {
"DRMOBILE": "8985180306",
"DIVCODE": 2,
"BRDCODE": 2,
"PRDCODE": 2,
"CREATEDON": "2017-08-10 11:38:22"
},
"ANSWERS": [{
"ADCODE": 1,
"ANSWER": "Excellent"
}, {
"ADCODE": 2,
"ANSWER": "Yes"
}, {
"ADCODE": 3,
"ANSWER": "No"
}, {
"ADCODE": 4,
"ANSWER": "Yes"
}, {
"ADCODE": 5,
"ANSWER": "Yes"
}, {
"ADCODE": 6,
"ANSWER": "No"
}, {
"ADCODE": 7,
"ANSWER": "2-4"
}, {
"ADCODE": 8,
"ANSWER": "15"
}]
},{
"DATA": {
"DRMOBILE": "8985180305",
"DIVCODE": 1,
"BRDCODE": 1,
"PRDCODE": 1,
"CREATEDON": "2017-08-10 11:38:22"
},
"ANSWERS": [{
"ADCODE": 1,
"ANSWER": "Excellent"
}, {
"ADCODE": 2,
"ANSWER": "Yes"
}, {
"ADCODE": 3,
"ANSWER": "No"
}, {
"ADCODE": 4,
"ANSWER": "Yes"
}, {
"ADCODE": 5,
"ANSWER": "Yes"
}, {
"ADCODE": 6,
"ANSWER": "No"
}, {
"ADCODE": 7,
"ANSWER": "2-4"
}, {
"ADCODE": 8,
"ANSWER": "15"
}]
},{
"DATA": {
"DRMOBILE": "8985180307",
"DIVCODE": 2,
"BRDCODE": 2,
"PRDCODE": 2,
"CREATEDON": "2017-08-10 11:38:22"
},
"ANSWERS": [{
"ADCODE": 1,
"ANSWER": "Excellent"
}, {
"ADCODE": 2,
"ANSWER": "Yes"
}, {
"ADCODE": 3,
"ANSWER": "No"
}, {
"ADCODE": 4,
"ANSWER": "Yes"
}, {
"ADCODE": 5,
"ANSWER": "Yes"
}, {
"ADCODE": 6,
"ANSWER": "No"
}, {
"ADCODE": 7,
"ANSWER": "2-4"
}, {
"ADCODE": 8,
"ANSWER": "15"
}]
}
]
哪一行是37行?你能提供完整的錯誤信息嗎? –
注意:數組到字符串轉換在C:\ xampp \ htdocs \ android \ testing \ krisapp \ test3.php在第37行這是錯誤消息得到 –