I have the following json string
$str = '{"icwsCallQueue":{"1002598152":{"AccoRDI_account_id":"","AccoRDI_mid":"","Eic_CallDirection":"O","Eic_CallIdKey":"100259815260150624","Eic_CallState":"Disconnected","Eic_ConferenceId":"","Eic_ConferenceMembers":"","Eic_ImmediateAccess":"1","Eic_LocalName":"Full Name","Eic_LocalUserId":"username","Eic_MonitorsCombinedCount":"0","Eic_Muted":"","Eic_ObjectType":"Call","Eic_ParentConferenceId":"","Eic_RemoteAddress":"307","Eic_RemoteName":"username-test","Eic_State":"I"},"1002598162":{"AccoRDI_account_id":"","AccoRDI_mid":"","Eic_CallDirection":"O","Eic_CallIdKey":"100259816260150624","Eic_CallState":"Disconnected","Eic_ConferenceId":"","Eic_ConferenceMembers":"","Eic_ImmediateAccess":"1","Eic_LocalName":"Full Name","Eic_LocalUserId":"username","Eic_MonitorsCombinedCount":"0","Eic_Muted":"","Eic_ObjectType":"Call","Eic_ParentConferenceId":"","Eic_RemoteAddress":"307","Eic_RemoteName":"username-test","Eic_State":"I"}}}';
If I decode it using json_decode($str)
I get the following
stdClass Object
(
[icwsCallQueue] => stdClass Object
(
[1002598152] => stdClass Object
(
[AccoRDI_account_id] =>
[AccoRDI_mid] =>
[Eic_CallDirection] => O
[Eic_CallIdKey] => 100259815260150624
[Eic_CallState] => Disconnected
[Eic_ConferenceId] =>
[Eic_ConferenceMembers] =>
[Eic_ImmediateAccess] => 1
[Eic_LocalName] => Full Name
[Eic_LocalUserId] => username
[Eic_MonitorsCombinedCount] => 0
[Eic_Muted] =>
[Eic_ObjectType] => Call
[Eic_ParentConferenceId] =>
[Eic_RemoteAddress] => 307
[Eic_RemoteName] => username-test
[Eic_State] => I
)
[1002598162] => stdClass Object
(
[AccoRDI_account_id] =>
[AccoRDI_mid] =>
[Eic_CallDirection] => O
[Eic_CallIdKey] => 100259816260150624
[Eic_CallState] => Disconnected
[Eic_ConferenceId] =>
[Eic_ConferenceMembers] =>
[Eic_ImmediateAccess] => 1
[Eic_LocalName] => Full Name
[Eic_LocalUserId] => username
[Eic_MonitorsCombinedCount] => 0
[Eic_Muted] =>
[Eic_ObjectType] => Call
[Eic_ParentConferenceId] =>
[Eic_RemoteAddress] => 307
[Eic_RemoteName] => username-test
[Eic_State] => I
)
)
)
The problem with this is that I can't access a property with only an integer. I can't do this $icwsCallQueue->100259152->Eic_State
so what I need to do some how is convert my decoded string to something like this
stdClass Object
(
[icwsCallQueue] => Array
(
[1002598152] => stdClass Object
(
[AccoRDI_account_id] =>
[AccoRDI_mid] =>
[Eic_CallDirection] => O
[Eic_CallIdKey] => 100259815260150624
[Eic_CallState] => Disconnected
[Eic_ConferenceId] =>
[Eic_ConferenceMembers] =>
[Eic_ImmediateAccess] => 1
[Eic_LocalName] => Full Name
[Eic_LocalUserId] => username
[Eic_MonitorsCombinedCount] => 0
[Eic_Muted] =>
[Eic_ObjectType] => Call
[Eic_ParentConferenceId] =>
[Eic_RemoteAddress] => 307
[Eic_RemoteName] => username-test
[Eic_State] => I
)
[1002598162] => stdClass Object
(
[AccoRDI_account_id] =>
[AccoRDI_mid] =>
[Eic_CallDirection] => O
[Eic_CallIdKey] => 100259816260150624
[Eic_CallState] => Disconnected
[Eic_ConferenceId] =>
[Eic_ConferenceMembers] =>
[Eic_ImmediateAccess] => 1
[Eic_LocalName] => Full Name
[Eic_LocalUserId] => username
[Eic_MonitorsCombinedCount] => 0
[Eic_Muted] =>
[Eic_ObjectType] => Call
[Eic_ParentConferenceId] =>
[Eic_RemoteAddress] => 307
[Eic_RemoteName] => username-test
[Eic_State] => I
)
)
)
so I can access the records like this $icwsCallQueue['100259152']->Eic_State
on the other hand if I decoded the string like this json_decode($str, true)
everything will be presented as array which is not what am I looking for.
Any idea on how to decode the string with array when array must be used and object when array can be avoided?