/    Sign up×
Community /Pin to ProfileBookmark

problem processing JSON of AJAX request

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’}

[/code]

$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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@gloosemoauthorJul 24.2011 — I'm sorry i seem to have figured it out.

There was a ; missing which threw everything off.

thanks for trying, G
×

Success!

Help @gloosemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...