I am having issues with a properly formatted json string, I believe. I am wondering if it is due to the construction of the query string, but it looks right to me, unless it’s an issue with the double brackets that are in the encoded json string below. Looking for an extra set of eyes.
Before json encoding, var_dump($considerationCodes) looks like:
array (size=2)
8 =>
array (size=13)
67 =>
array (size=1)
0 =>
array (size=3)
...
41 =>
array (size=1)
0 =>
array (size=3)
...
42 =>
array (size=1)
0 =>
array (size=3)
...
print json_encode($considerationCodes); looks like:
$considerationCodes =
{"8": {"67": [[ {"id":"64","description":"string description..."},{"id":"65","description":"string description..., "},{"id":"66","description":"string description..."} ]] , "41": [[ {"id":"64","description":"string description..."},{"id":"65","description":"string description..., "},{"id":"66","description":"string description..."} ]] }}
Json structure how it is expected/accepted (tested and works with raw data):
['8']['67']['64'] = "string description...";
['8']['67']['65'] = "string description...";
['8']['67']['66'] = "string description...";
['8']['41']['64'] = "string description...";
['8']['41’]['65'] = "string description...";
['8']['41']['66'] = "string description...";
...etc
And this is how I submit the json encode (tested and works with raw data):
return $this->renderText(json_encode( $considerationCodes[$appCode][$reasonCode] ) );
When I look at the results of this json submission (a multiple choice select input), it looks like:
[Object][object][Object][object][Object][object][Object][object]
What am I missing?
EDIT:
This is how I have constructed my arrays:
$reason_codes_ids = array();
foreach($all_reason_codes as $key => $values) {
$reason_codes_ids[] = $values['id'];
}
//wrap the consideration_info into each reason_id:
$codes_with_reasons = array();
foreach($reason_codes_ids as $value){
foreach($consideration_info as $key => $value1){
$codes_with_reasons[$value][$key] = $value1;
}
}
//the above results in: ['reason-code-id']['consideration-code-id'] = "consideration-code-answer":
//next, get the declined_app_status:
$declinedAppStatus = 8;
//then wrap the above results in a wraper for the declined application-code
$declinedConsiderationCodes = array();
foreach($codes_with_reasons as $key => $value)
{
$declinedConsiderationCodes[$declinedAppStatus][$key]=[$value];
}
$considerationCodes = $declinedConsiderationCodes;
and:
$consideration_info =
array (size=3)
0 =>
array (size=2)
'id' => string '64' (length=2)
'description' => string 'string...' (length=35)
1 =>
array (size=2)
'id' => string '65' (length=2)
'description' => string ''string...' (length=143)
2 =>
array (size=2)
'id' => string '66' (length=2)
'description' => string ''string...' (length=143)
$reason_codes_ids =
array (size=13)
0 => string '67' (length=2)
1 => string '41' (length=2)
2 => string '42' (length=2)
3 => string '43' (length=2)
4 => string '44' (length=2)
5 => string '45' (length=2)
6 => string '46' (length=2)
7 => string '47' (length=2)
8 => string '48' (length=2)
9 => string '49' (length=2)
10 => string '50' (length=2)
11 => string '51' (length=2)
12 => string '68' (length=2)
With proper formatting and indentation, your JSON string looks like this:
Notice that
['8']['67']is an array with numeric indexes. To do what it looks like you want to do, your JSON string should look more like this: (sample)And so your PHP array should look more like this: