2017-01-23 3 views
0

Вот как я получаю результат, пока я пытаюсь кодировать строку в формате JSON. Я хочу, что URL должен быть в этом: http://ipaddress/Up/user_images/549279.jpgJson string с кодировкой url или json для url

РЕЗУЛЬТАТ:

{ "результат": [{ "ID": "42", "имя": "HTTP: // IPADDRESS/Up/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); 
+0

http://stackoverflow.com/questions/4319105/remove-trailing-slash-from-string-php см это, это поможет – Anjali

ответ

0

попытка ниже кода

//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 
    $jsonData = json_encode($result); 
    echo $jsonData; // **MODIFIED LINE** 
    $r1 = json_decode($jsonData, true); // **MODIFIED LINE** 
    print_r($r1); 
    mysqli_close($con); 
+0

Мы не получаем приводятся в формате JSON. Мы получаем тот же результат, что и раньше, и rtrim также не работает – Vinny

+0

Спасибо за ваш повтор, я нашел ответ «$ jsonData = json_encode ($ result, JSON_UNESCAPED_SLASHES); \t echo $ jsonData; ' – Vinny