1

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'};

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use either var_dump() or print_r(). var_dump is preferable as it would print all levels of object hierarchy.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.