[HELP] Parse JSON using PHP
#1
Hi All,

I am a bit of a newbie. I am curretnly on Frodo.

I am trying to create a web page that is hosted within my own network. I want to return my list of latest movies using PHP. I have the following code and it is not working:

Code:
<?php

$response = file_get_contents("http://192.168.0.103/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetRecentlyAddedMovies\",\"id\":\"mybash\"}");
$result = json_decode($response, true);

for ($i = 0; $i <= 5; $i++) {

    echo $result[$i]['label'];
    echo "<br>";
}
?>

Unfortunately it is not parsing the latest 6 movies in my library... If I type the link
Code:
http://192.168.0.103/jsonrpc?request={"jsonrpc":"2.0","method":"VideoLibrary.GetRecentlyAddedMovies","id": "mybash"}

into my browser, I get code that looks like this:

Code:
{"id":"mybash","jsonrpc":"2.0","result":{"limits":{"end":105,"start":0,"total":105},"movies":[{"label":"A Thousand Times Good Night","movieid":1161},{"label":"Labor Day","movieid":1160},{"label":"The Nut Job","movieid":1159},{"label":"Braveheart","movieid":1158},{"label":"Zulu","movieid":1156},{"label":"55 Days at Peking","movieid":1155},{"label":"At Middleton","movieid":1153},{"label":"The Immigrant","movieid":1152},{"label":"Stand by Me","movieid":1151},{"label":"About Time","movieid":1150},{"label":"The Berlin File","movieid":1149},{"label":"Once Upon a Time in the West","movieid":1146},{"label":"Exit Through the Gift Shop","movieid":1143},{"label":"Rigor Mortis","movieid":...

With my PHP I should be able to get each of the "labels" above; but my list is empty.

Can someone please tell me what I am doing wrong?

Any advice is greatly appreciated.

Thanks,

Hernando
Image
Reply
#2
To answer my own question....

Code:
<?php

$response = file_get_contents("http://192.168.0.103/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetRecentlyAddedMovies\",\"id\":\"mybash\"}");
$wawa = substr($response,94);
$wawa = substr($wawa,0, -3);
$wawa= "[" .$wawa ."]";


$result = json_decode($wawa, true);
for ($i = 0; $i <= 15; $i++) {
    echo $result[$i]['label'];
    echo " = " . $result[$i]['movieid'] . "<br>";
}
?>

The string above really needs to be formatted with a starting "[" and the parameters section at the beginning does not allow the proper decoding. Not sure if this is going to help anyone.

I do have another question.... what would be the correct http code to get a specific movie info... I know the parameter "movieid" has to be passed... Ssay my movie id is 1160, I tried this link, but I get an error...

Code:
http://192.168.0.103/jsonrpc?request={ "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails","movieid":"1160" }

Can someone please help me with what the correct url would be.

Thanks again,

H.
Reply

Logout Mark Read Team Forum Stats Members Help
[HELP] Parse JSON using PHP0