Jump to content

json formatting


Danny620

Recommended Posts

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"
    },

Link to comment
https://forums.phpfreaks.com/topic/254621-json-formatting/
Share on other sites

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>';

Link to comment
https://forums.phpfreaks.com/topic/254621-json-formatting/#findComment-1305672
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.