i want to get the specific value from the json, but i can't get it to work. this is my save format, these are values from input fields.
$.ajax({
type: "POST",
url: "speichern.php",
dataType: 'json',
data: {
"Produkt": {
"Produktkategorie": Produktkategorie,
"Optionen": {
"MaxBreite": MaxBreite,
"MaxHoehe": MaxHoehe,
"MinBreite": MinBreite,
"MinHoehe": MinHoehe,
"ProduktStaerke": ProduktStaerke,
"KantenAuswahl": KantenAuswahl, },
"Formen": {
"FormRund": FormRund,
"FormEllipse": FormEllipse,
"FormHexagon": FormHexagon,
"FormSchnittlinks": FormSchnittlinks,
"FormRechtQuad": FormRechtQuad,
}
}
},
}).done(function( msg ) {
console.log( msg );
});
here it gets saved to file:
$neu = json_encode($_POST);
$file = file_get_contents('results.json');
$data = json_decode($file);
unset($file);
$data[] = $neu;
file_put_contents('results.json',json_encode($data));
unset($data);
and now i want to echo these values seperately:
$string = file_get_contents("results.json");
$jsonObject = json_decode($string);
$jsonArray = json_decode($string, true);
echo $jsonObject->Produkt->Produktkategorie . " and " . `$jsonArray['Produkt']['MaxBreite'];`
but this only throws me following errors:
for the object: Notice: Trying to get property of non-object in for the array: Notice: Undefined index: Produkt in
this is the complete json file:
["{\"Produkt\":{\"Produktkategorie\":\"TestArtikel\",\"Optionen\":{\"MaxBreite\":\"250\",\"MaxHoehe\":\"150\",\"MinBreite\":\"10\",\"MinHoehe\":\"5\",\"ProduktStaerke\":\"3\",\"KantenAuswahl\":\"Ecke\"},\"Formen\":{\"FormRund\":\"true\",\"FormEllipse\":\"true\",\"FormRechtQuad\":\"true\"}}}"]
could you help me please?