0

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

 <?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

rafaelc
  • 57,686
  • 15
  • 58
  • 82
Sumanth Jois
  • 3,146
  • 4
  • 27
  • 42

2 Answers2

1

You can access the object property by using the ->

<?php
    $jsonObject = json_decode($_GET["UserDetails"]);
    echo $jsonObject->Email; // will print joissumanh@gmail.com
?>
Robin Carlo Catacutan
  • 13,249
  • 11
  • 52
  • 85
1

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

<?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

Muthukumar Anbalagan
  • 1,138
  • 12
  • 15