Neeraj Kumar
Neeraj Kumar

Reputation: 504

How to decode json array in square bracket under curly bracket

I am unable to get array data between square bracket under curly bracket. This is json output:

{"data":{"user":[{"transaction":"45455","date":"2013-10-28" }],"msg":"ok"},"error":[]}

I have tried this:

$obj = json_decode($json_data, true);
$user_data_array = $obj['data']['user'];

But I am unable to get data in user array. Waiting for you quick reply and thanks in advance.

Upvotes: 1

Views: 2361

Answers (2)

Ronald Swets
Ronald Swets

Reputation: 1667

I assume the "ok" in the message should be a string? Right now your json is invalid.

$json_data = '{"data":{"user":[{"transaction":"45455","date":"2013-10-28"}],"msg":"ok"},"error":[]}';

$obj = json_decode($json_data, true);
$user_data_array = $obj['data']['user'];

Upvotes: 1

Krish R
Krish R

Reputation: 22721

$user_data_array = $obj['data']['user'][0]['transaction'];

Upvotes: 0

Related Questions