get value by key in JSON Topic is solved

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
neojw1505
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Wed Aug 11, 2021 12:44 pm

get value by key in JSON

Post by neojw1505 » Mon Jan 17, 2022 4:39 am

I have saved a subform data into JSON format and is trying to retrieve it from the database but the key in the JSON is shown as __field50, __field51 which makes it difficult to access the data I want.

The die dump looks like this -> https://prnt.sc/26ek19t

I would like to get the value of the 'module' property. Can anyone help me please?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 14587
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: get value by key in JSON

Post by toivo » Mon Jan 17, 2022 5:16 am

Why do you think it is difficult to access those keys? Are the values of those keys not predictable?

The dump shows the structure of the array in any case. Iterate through the array using foreach() and utilise the switch() statement inside the loop.
Toivo Talikka, Global Moderator

neojw1505
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Wed Aug 11, 2021 12:44 pm

Re: get value by key in JSON

Post by neojw1505 » Mon Jan 17, 2022 5:35 am

toivo wrote:
Mon Jan 17, 2022 5:16 am
Why do you think it is difficult to access those keys? Are the values of those keys not predictable?

The dump shows the structure of the array in any case. Iterate through the array using foreach() and utilise the switch() statement inside the loop.
I find it difficult to access those keys because it is dynamically increasing by 1 every time.

I would like to know if it is possible to store the all the 'module' property value into a new array;

neojw1505
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Wed Aug 11, 2021 12:44 pm

Re: get value by key in JSON

Post by neojw1505 » Mon Jan 17, 2022 5:58 am

Update: managed to use foreach loop and store the module property value into a new array.


Post Reply

Return to “Joomla! 4.x Coding”