如何获取字符串输出?当我尝试解码时发生了一个错误。我想在文本框中插入输出值。如何解码并从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