简体   繁体   中英

Laravel structuring JSON response

I am struggling to structure json response in Laravel, here's an example:

{
  "0": {
    "instagram": [
      {
        "description": "#trainedacademy taking a break. We will resume for business on Monday 😎 @nickyjanew 🌞",
        "time": "Wednesday 25th October",
        "image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/e15/22794071_716881718510905_8530561994892247040_n.jpg",
        "likes": 15,
        "comments": 0,
        "link": "https://www.instagram.com/p/Baq437_FRav/",
        "video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
      },
      {
        "description": "Jump into a #personaltraining #career! Started college and decided it’s not for you? Want to be a Gym Instructor? Circuit Trainer? Or work towards a career in the Fire Service? Join us Weds night for open enrolment or just get some careers advice from @paulalitherland and @nickyjanew \n@mahdloyouthzone 6:30pm Wednesday 8th November 2017. \nUCAS accredited \nindustry recognised \nExclusive discounts with the Fire Team badge \nFree food box @chiaproteinbar \nWork placements @thegymgroup",
        "time": "Sunday 8th October",
        "image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/22277977_106714113419553_5412239854790508544_n.jpg",
        "likes": 42,
        "comments": 2,
        "link": "https://www.instagram.com/p/BZ-WYZJloMY/",
        "video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
      },
      {
        "description": "#trainedacademy #team @mahdloyouthzone preparing marketing material for 2018 enrolments. #oldhamfitness #oldham #practical #learningenhanced #alevels #employability @gymcareer @thegymgroup @chiaproteinbar",
        "time": "Friday 6th October",
        "image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/22280199_2265489343466713_511544494877835264_n.jpg",
        "likes": 50,
        "comments": 0,
        "link": "https://www.instagram.com/p/BZ5hLU6FRzr/",
        "video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
      },

What I want to do is get rid of the "0": { part of the json. Is that possible?

    return response()->json(['count' => $count_instagram, ['instagram' => $instagramArray ]], 200);

You have to use like this:

return response()->json(['count' => $count_instagram, 'instagram' => $instagramArray ], 200);

Instead of

return response()->json(['count' => $count_instagram, ['instagram' => $instagramArray ]], 200);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM