这是我得到的结果,而我试图以JSON格式编码字符串。我想要的网址应该是这样的:http://ipaddress/Up/user_images/549279.jpg
JSON字符串与图像url或JSON格式的url编码
结果:
{ “结果”:[{ “ID”: “42”, “名”:“HTTP:// IP地址/上/ user_images/380289.jpg “},{” ID “:” 43" , “姓名”: “HTTP://IPADDRESS/Up/user_images/995062.jpg”},{ “ID”: “44”, “姓名” :“http://IPADDRESS/Up/user_images/171544.jpg”},{“id”:“41”,“name”:“http://IPADDRESS/Up/user_images/549279.jpg”}]}
警告:json_decode()预计参数1是串,阵列中的C中给出:\ XAMPP \ htdocs中\ JSN \ PHP_Scripts \上线getAllEmp.php 26
//creating a blank array
$result = array();
$r1 = array();
//looping through all the records fetched
while ($row = mysqli_fetch_array($r)){
//Pushing name and id in the blank array created
array_push($result,array(
"id"=>$row['userID'],
"name"=>$ur.$row['userPic'],
));
}
//Displaying the array in json format
echo json_encode(array('result'=>$result));
$r1= json_decode($result, true);
echo ($r1);
// echo json_decode(array("result"=>$r1));
mysqli_close($con);
http://stackoverflow.com/questions/4319105/remove-trailing-slash-from-string-php指这个,这将有助于 – Anjali