doushao1948 2016-10-22 13:38
浏览 508
已采纳

将json对象作为url参数传递

<?php  
  $jsonData = array(
    "comments" => "Fresh food",
    "container" => false,
    "cookedTime" => 2,
    "description" => "biryani",
    "refridgeration" => true,
    "serves" => 2,
    "veg" => true
);

json_encode($jsonData);
header("Location:Post.php?json=$jsonData");
?>

This is my php page which contains json object. I am passing this json object into another page Post.php.

<?php
$jsonData = $_GET['json'];
json_decode($jsonData, TRUE);
echo var_dump($jsonData);
?>

when I did a dump the result is C:\wamp\www\Hack\Post.php:16:string 'Array' (length=5). It is printing "Array" instead of the json object. What do I do?

  • 写回答

3条回答 默认 最新

  • dongzipu7517 2016-10-22 13:40
    关注

    When you do json_encode you must have a variable to store the result:

    $jsonData = json_encode($jsonData)
    

    Without this, your data is still just a php object

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)