0

Guys i have tried to get the JSON array value through PHP. its not returning any value

{
"transactionTime": "2015-11-14T03:36:11-08:00",
"receipt": "********",

"lineItems": [
    {
        "itemNo": "1",

    }
],

}

in PHP i have tried this code

Here $decrypted contains the above formatted JSON value.

$order = json_decode($decrypted);
$id = $order['transactionTime'];

Could anyone look at it . thanks guys

2 Answers 2

1

Try this:

$order = json_decode($decrypted, true);
$id = $order['transactionTime'];

Edited

When you set assoc parameter in json_decode() function to TRUE, the returned objects will be converted into associative arrays.

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

6 Comments

I have removed the comma $id = $order['lineItems']['itemNo']; is that correct to get itemNo value ?? because its not getting the value..
yes, that's correct. That should give you the itemNo. By the way, as @n-dru pointed out, your json is incorrect, please remove the trailing comma after "itemNo": "1" and after final ]. You can validate your json here
You json is valid, and oh! I was wrong, since lineItems is an array, this is what you would do to get itemNo, $id = $order['lineItems'][0]['itemNo'];.
Happy to hear. Please upvote and accept the answer. :)
Hey buddy $cbemail = $order['customer']['billing']['email']; doesnot return any value ??
|
0

Your json string is invalid - remove trailing comma after "itemNo": "1" and after final ].

1 Comment

Here the complete string textuploader.com/56wwg

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.