【问题标题】:Pass jsondata in url as array [duplicate]将url中的json数据作为数组传递[重复]
【发布时间】:2018-01-30 05:42:20
【问题描述】:

如何在 php 中的 URL 中传递 jsondata,我搜索并尝试使用 http_build_query() 它是这样传递的

    http://abcd/xyz?id=12&name=mansfh

但我希望网址是这样的

    http://abcd/xyz?jsondata={"id":"12","name":"mansfh"} 

请有人帮帮我

【问题讨论】:

  • java 和 php 的 urlencode 没有太大的变化,看下面的回答,可能会有帮助

标签: php


【解决方案1】:

尝试使用 url 编码,值得一试

<?php
$json_str = "{'id':'12','name':'mansfh'}";
$url_json = urlencode($json_str);
$url = "http://abcd/xyz?jsondata={$url_json}";

//to get the JSON again in http://abcd/xyz page

$json_str = urldecode($_GET['jsondata']);

?>

【讨论】:

  • 这是我所期望的。谢谢 Sathish Kumar D.
【解决方案2】:

试试这个

<a href= 'http://abcd/xyz?jsondata={"id":"12","name":"mansfh"}' target="_blanck">a</a>

https://jsfiddle.net/eudgyj3u/

【讨论】:

    猜你喜欢
    • 2015-02-19
    • 1970-01-01
    • 2010-12-18
    • 2016-05-13
    • 2013-07-24
    • 1970-01-01
    • 2017-03-04
    • 2021-12-27
    相关资源
    最近更新 更多