I have the following JSON file as input,
{ "$type": "NanoWebInterpreter.WebInputData, NanoWebInterpreter", "NBBList": { "$type": "System.Collections.Generic.List`1[[monoTNP.Common.NBB, monoTNP.Common]], mscorlib", "$values": [ { "$type": "monoTNP.Common.NBB, monoTNP.Common", "ID": "id-0065-00000003", "MPList": { "$type": "System.Collections.Generic.List`1[[monoTNP.Common.MP, monoTNP.Common]], mscorlib", "$values": [ { "$type": "monoTNP.Common.EllipticalMP, monoTNP.Common", "Eccentricity": 1.0, "ID": "id-0065-00000006", "ParticleIndex": -1, "DispersionInteractionStrength": 0.0, "DispersionInteractionRange": 2.5, "CharacteristicSize": 0.0, "CenterOfMass": "<0,0,0>", "OrientationVector": "<>" }, { "$type": "monoTNP.Common.CubeMP, monoTNP.Common", "ID": "id-0065-00000005", "ParticleIndex": -1, "DispersionInteractionStrength": 0.0, "DispersionInteractionRange": 2.5, "CharacteristicSize": 0.0, "CenterOfMass": "<0,0,0>", "OrientationVector": "<>" }, { "$type": "monoTNP.Common.CircularMP, monoTNP.Common", "ID": "id-0065-00000004", "ParticleIndex": -1, "DispersionInteractionStrength": 0.0, "DispersionInteractionRange": 2.5, "CharacteristicSize": 0.0, "CenterOfMass": "<0,0,0>", "OrientationVector": "<>" } ] },
and etc.
My ultimate goal is to trace this tree recursively, wrapping each key / object name with <ul> tags and properties at the "ParticleIndex" level in some kind of <form> structure, but I canโt figure out how to index $ arrays into arrays.
This is the code I manipulated to find out how each element (object or array) is accessed:
foreach ($json->NBBList->'$values'[0] as $key => $value){ var_dump($key); echo "\n".var_dump($value); echo "\n\n\n"; }
This obviously does not work, because the index of values โโis outside the line, but when it is inside, PHP interprets it as part of the line.
Is there any way for me to index each element of the $ values โโarray and, ultimately, in a for loop?
I think using a true JSON decoding property might be a better solution ...