Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want echo value json_encode by json_decode, how is it?
Following php code is my try that not work:
$json = '[{"dg_j":"1390\/02\/05","dg_sh":"2011\/4\/25"}]'; $obj = json_decode($json); echo $obj->{'dg_j'}; echo '<br>'; echo $obj->{'dg_sh'};
What you've got is actually an array that contains a single object. You'd want
$obj[0]->dg_j
Doing a var_dump($obj) will show you what the JSON actually turned into.
var_dump($obj)
Add a comment
You can use either var_dump() or print_r(). var_dump is preferable as it would print all levels of object hierarchy.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.