Try to parse JSON strings into an array. Because this response is not totaly a valid JSON string try to insert this into a new array to parse a valid JSON string.
Such as: {"main_container": [ --> YOUR POSTED CODE <-- ]}
<?php
$jsonResponse = '{"main_container": [
{
"id": 235322185,
"original_id": 190991409,
"defindex": 19,
"level": 1,
"quality": 4,
"inventory": 70,
"quantity": 1,
"rarity": 4,
"attributes": [
{
"defindex": 6,
"value": 1130627072,
"float_value": 228
},
{
"defindex": 7,
"value": 1148436480,
"float_value": 975
},
{
"defindex": 8,
"value": 1031063904,
"float_value": 0.059762358665466309
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_smg_p90_mag.mdl"
}
]
},
{
"id": 236527226,
"original_id": 236502674,
"defindex": 27,
"level": 1,
"quality": 9,
"inventory": 82,
"quantity": 1,
"rarity": 3,
"attributes": [
{
"defindex": 6,
"value": 1133608960,
"float_value": 291
},
{
"defindex": 7,
"value": 1142240880,
"float_value": 596.8505859375
},
{
"defindex": 8,
"value": 994750258,
"float_value": 0.0030927178449928761
},
{
"defindex": 80,
"value": 0,
"float_value": 0
},
{
"defindex": 81,
"value": 0,
"float_value": 0
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_shot_mag7_mag.mdl"
}
]
},
{
"id": 236529059,
"original_id": 136971214,
"defindex": 35,
"level": 1,
"quality": 4,
"inventory": 77,
"quantity": 1,
"rarity": 2,
"attributes": [
{
"defindex": 6,
"value": 1077936128,
"float_value": 3
},
{
"defindex": 7,
"value": 1141712676,
"float_value": 564.611572265625
},
{
"defindex": 8,
"value": 1031160533,
"float_value": 0.060122329741716385
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
}
]
}
]}
';
$jsonDecodeArray = json_decode($jsonResponse, true);
foreach($jsonDecodeArray as $mainContainerItems){
// LOOP THROUGH ALL ITEM GROUP. IN THIS CASE WE HAVE 3 ITEM GROUPS IN
// $mainContainerItems ARRAY
foreach($mainContainerItems as $inventoryItem){
echo $inventoryItem['id']; // will return for example: 236529059
echo $inventoryItem['original_id']; // will return for example: 136971214
echo $inventoryItem['defindex'];
}
}
?>
In this case the resoult will be a multi dimensional array, where you can loop through with multiple foreach.
The resoult is:
$jsonDecodeArray contains the main_container array with all items, where a single item is also an array.
$inventoryItem contains a single item with it's all properties. Like shown below.
Array
(
[id] => 236529059
[original_id] => 136971214
[defindex] => 35
[level] => 1
[quality] => 4
[inventory] => 77
[quantity] => 1
[rarity] => 2
[attributes] => Array
(
[0] => Array
(
[defindex] => 6
[value] => 1077936128
[float_value] => 3
)
[1] => Array
(
[defindex] => 7
[value] => 1141712676
[float_value] => 564.61157226562
)
[2] => Array
(
[defindex] => 8
[value] => 1031160533
[float_value] => 0.060122329741716
)
[3] => Array
(
[defindex] => 147
[value] => models/weapons/stattrack.mdl
)
)
)