简体   繁体   English

从用户的php中的URL解码Json Object

[英]Decode Json Object from a url in php coming from a user

hey i am making an android app where user's request in the format of json . 嘿,我正在制作一个android应用,其中用户的请求格式为json。 Their request will look like this.. 他们的要求将如下所示。

  JSONObject j = new JSONObject(createJson());
          String  url ="http://codemoirai.esy.es/test.php?UserDetails="+j;

  Where j = {"Email":"code@gmail.com","Username":"xyz","Password":"xyz"}

This is what I will be sending to the test.php , i want to know how i can fetch this data and display it using php. 这是我将发送到test.php的内容,我想知道如何获取此数据并使用php显示它。

  <?php
require "init1.php";



$jsonObject = $_GET["UserDetails"];
$obj = json_decode($jsonObject);
$email = $obj->Email;
 $password = $obj->Password;
.......


echo $email; //Everthing i fetch from jsonObject is null. Why?


?>

ThankYou, is it correct how i am fetching in php?? 谢谢,我在php中获取的方式正确吗?

In test.php you can catch the data with $_GET['UserDetails'] then decode it with json_decode($_GET['UserDetails') 在test.php中,您可以使用$_GET['UserDetails']捕获数据,然后使用json_decode($_GET['UserDetails')对其进行解码

Then you can iterate it with a foreach loop 然后,您可以使用foreach循环对其进行迭代

Example: 例:

if(isset($_GET['UserDetails'])) {
     $details = json_decode($_GET['UserDetails']);

      foreach($details as $key => $val) {
           echo $key.' = '.$val;
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM