unemployment Posted August 9, 2012 Share Posted August 9, 2012 Do you guys know how I can get php to return this JSON Object properly? My current script fails. <?php if (isset($_GET['page']) && $_GET['page'] == "featured") { ?> { "equipments" : [ {"id" : 1234567, "name" : "Articulating Boom Lift", "specUrl" : "/data/spec/equip1.pdf", "summary" : "Varying heights: 20' - 60' with emissions free operation, heights to 80' with diesel/dual fuel systems and 150' with diesel; Available in electric, gas, propane or diesel; Large work platforms with up to 500 lb. capacity; 4-wheel drive and rough terrain models available.", "description" : "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", "quantity" : 1, "existInCart" : false, "cartTransactionId" : 6509299203 } ] } <?php } if (isset($_GET['page']) && $_GET['page'] == "tropical") { ?> { "equipments" : [ {"id" : 55727, "name" : "Bucket Truck", "specUrl" : "/data/spec/equip1.pdf", "summary" : "Available two man platforms; Platform leveling system; Available height range 34' - 51'; Outrigger & backup warning alarms; Tool lines at boom; 12V emergency operating system", "description" : "Equipment availability may be limited and rental rates are subject to change without notice. Taxes and additional costs and or fees, such as refueling, Loss and Damage Waiver, and delivery are extra when applicable. All terms and conditions of the Hertz Equipment Rental contract will apply.", "quantity" : 1, "existInCart" : false, "cartTransactionId" : 6509299222 } ] } <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266875-need-php-to-return-my-json-object/ Share on other sites More sharing options...
scootstah Posted August 9, 2012 Share Posted August 9, 2012 json_encode and json_decode Quote Link to comment https://forums.phpfreaks.com/topic/266875-need-php-to-return-my-json-object/#findComment-1368180 Share on other sites More sharing options...
unemployment Posted August 9, 2012 Author Share Posted August 9, 2012 I don't get it. Do I have to make it an array in php first and then convert it to JSON? I only want this for testing so I didn't really want to convert it if I didn't have to. Quote Link to comment https://forums.phpfreaks.com/topic/266875-need-php-to-return-my-json-object/#findComment-1368182 Share on other sites More sharing options...
scootstah Posted August 9, 2012 Share Posted August 9, 2012 Yes. But you can convert a JSON object to a PHP variable with json_decode(). Quote Link to comment https://forums.phpfreaks.com/topic/266875-need-php-to-return-my-json-object/#findComment-1368183 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.