Danny620 Posted January 8, 2012 Share Posted January 8, 2012 Im using /* output in necessary format */ header('Content-type: application/json'); echo json_encode($offers); to output json object but it formats like so [{"id":"31","url":"nifty-advertising","views":"72","image":"1325926551.jpg","title":"Advertise With Nifty For Less Than A \u00a31.00 A Day","savings":"18","expr":"Mon, 31 Dec 2012"},{"id":"29","url":"scuba-try-dive-in-oldham","views":"141","image":"1325865579.jpg","title":"Probe Diving Offering A 50% Discount On A Try Dive!","savings":"50","expr":"Mon, 31 Dec 2012"},{"id":"30","url":"middleton-driving-school-phil-king","views":"113","image":"1325870912.jpg","title":"Middleton Driving School - Phil King Offers 50% Off First Lesson","savings":"50","expr":"Mon, 31 Dec 2012"},{"id":"28","url":"howards-domestics-cleaning","views":"354","image":"1325549893.jpg","title":"FREE Cleaning Offered By Howard's Domestics","savings":"100","expr":"Mon, 31 Dec 2012"},{"id":"27","url":"royton-car-services","views":"341","image":"1325549209.jpg","title":"FREE 28 Point Vehicle Health Check Ready For Winter","savings":"100","expr":"Sat, 31 Mar 2012"},{"id":"17","url":"chadderton-tyres-car-wash","views":"246","image":"1325534798.jpg","title":"Chadderton Tyre And Car Wash Offer Free Fitting On All Tyres","savings":"100","expr":"Sat, 31 Mar 2012"}] how can i get it to format like this [ { "id": "31", "url": "nifty-advertising", "views": "72", "image": "1325926551.jpg", "title": "Advertise With Nifty For Less Than A £1.00 A Day", "savings": "18", "expr": "Mon, 31 Dec 2012" }, Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/ Share on other sites More sharing options...
scootstah Posted January 8, 2012 Share Posted January 8, 2012 It already is. Whitespace doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305630 Share on other sites More sharing options...
Danny620 Posted January 9, 2012 Author Share Posted January 9, 2012 Hi, I need it to be screen friendly read Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305633 Share on other sites More sharing options...
Danny620 Posted January 9, 2012 Author Share Posted January 9, 2012 please see http://www.niftyuk.com/app/offers-json.php http://jsonlint.com/ - i used this to format it Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305635 Share on other sites More sharing options...
blacknight Posted January 9, 2012 Share Posted January 9, 2012 i have to ask why..... json code is normaly passed so that you run it thru your webpage and display the info the average user wont see it .... Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305639 Share on other sites More sharing options...
scootstah Posted January 9, 2012 Share Posted January 9, 2012 Use pre tags. $json = '[ { "id": "31", "url": "nifty-advertising", "views": "72", "image": "1325926551.jpg", "title": "Advertise With Nifty For Less Than A £1.00 A Day", "savings": "18", "expr": "Mon, 31 Dec 2012" }, { "id": "29", "url": "scuba-try-dive-in-oldham", "views": "141", "image": "1325865579.jpg", "title": "Probe Diving Offering A 50% Discount On A Try Dive!", "savings": "50", "expr": "Mon, 31 Dec 2012" }, { "id": "30", "url": "middleton-driving-school-phil-king", "views": "113", "image": "1325870912.jpg", "title": "Middleton Driving School - Phil King Offers 50% Off First Lesson", "savings": "50", "expr": "Mon, 31 Dec 2012" }, { "id": "28", "url": "howards-domestics-cleaning", "views": "354", "image": "1325549893.jpg", "title": "FREE Cleaning Offered By Howard\'s Domestics", "savings": "100", "expr": "Mon, 31 Dec 2012" }, { "id": "27", "url": "royton-car-services", "views": "341", "image": "1325549209.jpg", "title": "FREE 28 Point Vehicle Health Check Ready For Winter", "savings": "100", "expr": "Sat, 31 Mar 2012" }, { "id": "17", "url": "chadderton-tyres-car-wash", "views": "246", "image": "1325534798.jpg", "title": "Chadderton Tyre And Car Wash Offer Free Fitting On All Tyres", "savings": "100", "expr": "Sat, 31 Mar 2012" } ]'; echo '<pre>' . $json . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305672 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.