s0c0 Posted November 28, 2007 Share Posted November 28, 2007 I am using the Services_JSON class since we are running PHP 4.3. I have successfully converted simple arrays from javascript to json to php and then back again in fiddling around with this, but now I am actually trying to do something useful. In javascript I have built an array of objects like so: productsArr[prodCount] = new product_Constructor(id,product,price,fluxCost,discountable,qty,taxable,1); the "prodCount" variable is simply an auto-incrementing integer used for unique array indexes and the "product_Constructor" is just the constructor for my product object, the object is stored in and referenced by the array index. Don't concern yourself with where I get the variables I pass into the constructor as this works fine. Using an Ajax HTTP POST I pass this array over server side, the array ends up looking like this: [null,{"id":"4534","name":"MaMa Lotion Trial Pack","price":"8.95","fluxCost":"3.3","discountable":"0","qty":"1","taxable":"0","inCart":1},{"id":"290","name":"SkinCareRx Kit for Men","price":"65.00","fluxCost":"32.5","discountable":"0","qty":"1","taxable":"0","inCart":1}] When it hits the php side I use the following code: $productsArr = $this->json->decode(stripcslashes($productsJSON); // build array from json text foreach($productsArr as $prod) { echo $this->json->decode($prod); } But I get nothing. If I echo out the json text my PHP function receives it mirrors what was sent. If I do a print_r on the array it shows empty elements. Not even the json text is present in anywhere in the array. Why is this? Now before you question me, an array of objects was not my first choice. My initial choice was a multidimensional array to be converted into json text and then passed into PHP. I had problems converting a multidimensional array into json text with the latest version the json.js file though. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/79326-help-with-converting-json-array-and-objects-into-php-array-and-objects/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.