0

I am trying to format the data passed by the api in to key value paris for use with javascript the data right now is one big key and not in key value paris how can i get the data as key value paris and properly formated ?

<?php

     header('Content-Type: application/json; charset=utf-8');
    $url = file_get_contents('https://www.jiosaavn.com/api.php?_format=json&query=mere%20angne%20mein&__call=autocomplete.get');
    $data = explode('[', $url);
    $format = json_encode($data[1], true);
    print_r($format);

    ?>
2
  • There is no question here Commented May 24, 2020 at 20:08
  • updated the text Commented May 24, 2020 at 20:14

2 Answers 2

1

The response contains some HTML which has to be removed to be able to parse the json. This can be achieved with strip_tags. After removing the html json_decode can be used to get the values:

<?php
$content = file_get_contents('https://www.jiosaavn.com/api.php?_format=json&query=mere%20angne%20mein&__call=autocomplete.get');

$content = strip_tags($content);
$response = json_decode($content);

print_r($response);

foreach($response->albums->data as $album){
  echo $album->title;
}

result:

Mere Angne MeinLaawarisMere Angne MeinMere Angne Mein (From "Mere Angne Mein")Mere Angane Mein

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

Comments

0
$url = 'https://www.jiosaavn.com/api.php_format=json&query=mere%20angne%20mein&__call=autocomplete.get';
    $data = file_get_contents($url);
    $format = json_decode($data);
    print_r($format);

1 Comment

Please add the explanation why this answer is correct

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.