-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 [].

1
  • 1
    JSON arrays never have key value pairs. Your JSON is incorrect. Commented Jan 6, 2019 at 8:46

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.