A
A
Alina2016-11-24 17:47:04
JSON
Alina, 2016-11-24 17:47:04

How to get JSON response into a variable?

The response to the request comes in this form:
"message": {
"headers": {
"to": "",
"message-id" : "[email protected]",
"from": "John Doe ",
"subject " : "Test Subject"
$subject = $dok2[$i]->message->headers->subject; - everything is fine here
$message-id = $dok2[$i]—>message->headers->message-id; - it doesn't work here,
writes an error:
Notice: Undefined property: stdClass::$message in /home........
Notice: Use of undefined constant id - assumed 'id'....
it is id separately from message sees because of the hyphen in the message-id name.
How to fix? This is not stored in a variable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2016-11-24
@rivaufa

$messageId = $dok2[$i]—>message->headers->{'message-id'}

do you have php? hyphen is not allowed in variable names it is
better to decode json into an array json_decode($data, true)
and work with the array
$messageId = $dok2[$i]['message']['headers']['message-id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question