K
K
Kitaro22019-02-24 00:30:43
JavaScript
Kitaro2, 2019-02-24 00:30:43

Objects. How to get object key and nested object key?

Hello, I have little experience in working with objects and arrays, but I hope I will explain the essence clearly ...
I receive a callback from the server that looks like this:
5c71a7cf4984e993089607.jpeg
We need only the keys of the parent and child object. And is it possible to give names to the keys of the object and the child object?
For example, what would look like this:
{device_id:11841221:{ user_id: 11853024, user_id: 1183211, user_id: 12312123}}?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Esin, 2019-02-24
@Kitaro2

$json = json_decode($response, true);
the second argument of the method will immediately return you a dictionary instead of an object, with keys instead of object field names. You can loop through it as you like and do whatever you want with it.

P
Pavel Kornilov, 2019-02-24
@KorniloFF

Here, I once described a similar problem -

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question