Zelí
Zelí

Reputation: 121

php decode JSON get values

I'm trying to decode JSON format

What I am sending is:

{
"id": 123,
"name": "John",
“surname”: “Smith”,
“department”: 3
}

I am sending POST with data via Postman, in the picture.
So, this is the data I want to decode:

"data_serever_received": "{ \"id\": 123, \"name\": \"john\", “surname”: “Smith”, “department”: 3 }"

enter image description here

I tried

$this->input->data["id"]

but it is not working.

How can I get the id, name, surname and etc. values?

Upvotes: 0

Views: 812

Answers (2)

Quentin
Quentin

Reputation: 944008

Your JSON is invalid and are not ".

(Zoom in with your browser if you can't see the difference).

You need to start with valid JSON before you can parse it.

Upvotes: 3

silversunhunter
silversunhunter

Reputation: 1269

You can use json_decode to make it an array.

$json_array = json_decode($json_object);//$json_object will need to contain your json string.

then you can access like this:

echo $json_array["data"][“surname”];

PHP Doc on json_decode: http://php.net/manual/en/function.json-decode.php

Upvotes: 0

Related Questions