-1

how i can to change a key on json to array with one value in laravel. i send api for android app and i need to send all data In the form of list to read in android. for example:

{
  data1: {
    d1: "aaaaaaaaaaa"
  }
  data2: [
    d11: "ccccccccccc"
    d12: "jjjjjjjjjjj"
  ]
}

convert to:

{
  data1: [
    d1: "aaaaaaaaaaa"
  ]
  data2: [
    d11: "ccccccccccc"
    d12: "jjjjjjjjjjj"
  ]
}

change data1 to array and use this [].

Masoud Zarjani
  • 410
  • 1
  • 8
  • 19

1 Answers1

3

you need to provide second parameter of the json_decode() function which is as assoc flag

assoc
When TRUE, returned objects will be converted into associative arrays.

so in your case
json_decode($yourJson, true)

AH.Pooladvand
  • 1,944
  • 2
  • 12
  • 26