如何獲取字符串輸出?當我嘗試解碼時發生了一個錯誤。我想在文本框中插入輸出值。如何解碼並從json獲取字符串值
怎麼辦?
$array=json_decode($json);
echo $array;
**Warning:**
json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\school\vijay\update.php on line 20
我的PHP
<?php
$json = array();
$con=mysql_connect("localhost","school","certify");
$db_select = mysql_select_db('School_Data', $con);
$childid = $_GET['childid'];
$result = mysql_query("SELECT * FROM childinfo where ChildID='$childid'",$con);
while($r = mysql_fetch_assoc($result)) {
$json[] = $r;
}
if($result){
echo json_encode($json);
}
else
{
echo mysql_error();
}
//$obj = unserialize($json);
$arrayOfEmails=json_decode($json);
echo $arrayOfEmails;
mysql_close($con);
?>
我的JSON輸出
[{
"ID": "1",
"ChildID": "1001",
"ParentID": "2002",
"SiblingsID": "hfh",
"TeacherID": "hfhf",
"ChildName": "fhfh",
"DOB": "2014-03-04",
"Age": "0",
"Gender": "male",
"Grade": "KG1",
"Section": "KG1",
"Stream": "NORMAL",
"BloodGroup": "O-",
"Nationality": "KG1",
"Country": "Lebanon",
"Religion": "KG1",
"MotherTongue": "KG1",
"FirstLanguage": "bfbf",
"SecondLanguage": "fbfbfb",
"PlaceOfBirth": "fhfh",
"LandlineNumber": "0",
"EmailID": "[email protected]",
"ChildPhoto": "Requirement.PNG",
"TemporaryAddress": "bfdbd",
"PermanentAddress": "bdbdbf",
"Mentor": "fbbfd",
"DateOfJoin": "2014-03-06",
"JoinGrade": "J",
"ReferredBy": "bdbf",
"ContactNumber": "0",
"EmergencyContactNumber": "0"
}]
'$ arrayOfEmails'是一個對象,你不能直接'echo'出來。 –
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –
然後我怎樣才能得到文本框中的各自輸出 – user3317807