the following JSON is sent to “processcountertop.php”:
{“onSuccess”:””,”url”:”../ajax/processcountertop.php”,”methodType”:”post”,”queryType”:”SELECT”,”processMe”:{“food”:”abc”,”brand”:”My Food Company”,”ftype”:”Baby Foods”,”portionnum”:1,”portionname”:”portion”,”foodArrayLength”:1,”foodArray”:[{“id”:”3″,”food”:”Boneless Chicken Breast”,”brand”:”Generic”,”ftype”:”Meat – Poultry & Egg Products”,”sa”:”1 breast”,”ss”:”125 g”,”cal”:”110″,”fat”:”2″,”sat”:”0.5″,”trans”:”0″,”chol”:”65″,”sod”:”650″,”carb”:”0″,”fib”:”0″,”sug”:”0″,”pro”:”22″,”product”:”1″,”prodtype”:”1″,”comb”:”no”,”ssunit”:””,”portion”:”1 portion”}],”amountArray”:[[“1 breast”,1,0]]}}
so the real meat of the JSON starts at the “processMe” property, which is itself an object containing its own properties, as well as 2 different arrays, one is “foodArray”, is an array of objects with their own set of properties, the second is “amountArray”, which is an array of arrays.
i need to process this in php. i have the following code in processcountertop.php:
[code]
$objReceived = json_decode(urldecode($passme));
// passme is the name of the JSON string that is passed.
$url = $objReceived->{‘url’}
$queryType = $objReceived->{‘queryType’}
$processMe = $objReceived->{‘processMe’}
$url and $queryType get the correct properties of the object that was passed. but the problem when i try to assign the processMe object to $processMe. If i then try to echo (“$processMe->food”) it should output “abc” but instead i get an error unexpected T_VAR.
How can i access this object that is a property of the object passMe? is it actually converted to an array? I also try to echo (“$processMe[0]”) which is the same problem.
Thanks, G