0

I tried several times to echo a JSON object, with explode() function, but I did not succeed. I think I'm using a wrong method, but I can not find another way to do it.

I want to echo a JSON like:

{
    "Title_Book": "Harry Potter",
    "Volume": [
        {
            "Name": "Harry Potter and the Philosopher's Stone",
            "Actor": [
                {
                    "Actor": "Actor0"
                },
                {
                    "Actor": "Actor1"
                }
            ]
        },
        {
            "Name": "Harry Potter and the Chamber of Secrets",
            "Actor": [
                {
                    "Actor": "Actor0"
                }
            ]
        }
    ]
},
{
 "Title_Book" : Another Book
  ... 
}

As:

Title : Book
Volume[0][0] : Name of the book : Harry Potter and the Philosopher's Stone
Volume[0][1] : Actor 1
Volume[0][2] : Actor 1 
Volume[1][0] : Name of the book : Harry Potter and the Chamber of Secrets
Volume[1][1] : Actor 0 

Title1 ...
1
  • Looks like you have to remove keys on the Volume array. Am I right? Commented Nov 3, 2019 at 12:57

1 Answer 1

1

use json_decode with second parameter set to true.

example code:

$booksArray = json_decode($libraryJsonString,true);

foreach ($booksArray as $books) {

    print_r($books);

}

instead of print_r($booksArray); you may put another foreach loop to iterate over every element of the array. to see how the array looks stright after decoding it use:

$booksArray = json_decode($libraryJsonString,true);
print_r($booksArray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.