解码php中的Json字符串[复制]

时间:2021-07-04 07:25:50

This question already has an answer here:

这个问题在这里已有答案:

I want to know how i can acess this decoded Json and this is my code

我想知道我如何能够访问这个解码过的Json,这是我的代码

 <?php

    $jsonObject = $_GET["UserDetails"];

    ?>

Where jsonObject = {\"Email\":\"joissumanh@gmail.com\"}

How can i decode this above Json and acess it. Looking forward for a indepth Answer. ThankYou

我怎样才能解码上面的Json并获取它。期待深入的答案。谢谢

2 个解决方案

#1


1  

You can access the object property by using the ->

您可以使用 - >访问对象属性

<?php
    $jsonObject = json_decode($_GET["UserDetails"]);
    echo $jsonObject->Email; // will print joissumanh@gmail.com
?>

#2


1  

Once you use json_decode() function, then the assigned variable becomes PHP stdClass, which can be access as below.

一旦你使用了json_decode()函数,那么赋值的变量就变成了PHP stdClass,可以如下访问。

<?php

$jsonAsString = '{"Email": "username@domainname.tld"}';

$jsonObj = json_decode($jsonAsString);

// Now $jsonObj is a stdClass Object which can be accessed as below

echo $jsonObj -> Email;

?>

Clickhere to see sample http://ideone.com/E28wUS

点击查看示例http://ideone.com/E28wUS

#1


1  

You can access the object property by using the ->

您可以使用 - >访问对象属性

<?php
    $jsonObject = json_decode($_GET["UserDetails"]);
    echo $jsonObject->Email; // will print joissumanh@gmail.com
?>

#2


1  

Once you use json_decode() function, then the assigned variable becomes PHP stdClass, which can be access as below.

一旦你使用了json_decode()函数,那么赋值的变量就变成了PHP stdClass,可以如下访问。

<?php

$jsonAsString = '{"Email": "username@domainname.tld"}';

$jsonObj = json_decode($jsonAsString);

// Now $jsonObj is a stdClass Object which can be accessed as below

echo $jsonObj -> Email;

?>

Clickhere to see sample http://ideone.com/E28wUS

点击查看示例http://ideone.com/E28wUS