我有这个网址 -
http://localhost/app_demo/sample.php?jsonRequest={"GenInfo":{"type":"Request","appname":"XXX","appversion":"1.0.0"},"searchDish":{"userId":"295","dishName":"","est":"Pizza & Wings","location":"","type":"","priceRange":"","deviceos":"value","deviceId":"<UDID>","deviceType":"value","pageNo":"1"}}
当我点击此网址并打印
时print_r($_REQUEST['jsonRequest']);
仅打印字符串
{"GenInfo":{"type":"Request","appname":"XXX","appversion":"1.0.0"},"searchDish":{"userId":"295","dishName":"","est":"2 Pizza
我在网上搜索但没有得到答案。这是什么解决方案? 请帮忙, 感谢。
答案 0 :(得分:4)
查询字符串通常由键/值对组成,查询字符串的开头是问号(?),然后所有对都用&符号(&amp;)分隔。在您的值中使用&符就像启动一个新参数。
但是,这不是正确的方法。您不应该将JSON放在查询字符串中。
如果真的在查询字符串中必须有&符号,请使用%26 而不是&amp; amp 。 %26是&符号的十六进制值。
答案 1 :(得分:2)
您应该发出POST请求而不是GET请求:
答案 2 :(得分:1)
字符“&amp;”是问题,因为它是保留的。 (是查询字符串params分隔符) 在您的GET请求中使用之前,您必须“urlencode”您的字符串。所以像&amp;转换。但是当jValdron指出它时你不应该把JSON放在查询字符串中,但你可以这样做。
所以你urlencode字符串:
$url = 'http://localhost/app_demo/sample.php?jsonRequest=';
$jsonRequest = urlencode('{"GenInfo":{"type":"Request","appname":"XXX","appversion":"1.0.0"},"searchDish":{"userId":"295","dishName":"","est":"Pizza & Wings","location":"","type":"","priceRange":"","deviceos":"value","deviceId":"<UDID>","deviceType":"value","pageNo":"1"}}');
$url .= $jsonRequest;
然后你urldecode
print_r(urldecode($_REQUEST['jsonRequest']));
同样,您不应将JSON放在查询字符串中。