I'm trying to use uTorrent webUI API. I think this is a pretty n00b question but there's little documentation about this API on the web, sorry.
my server uses file_get_contents($url) and I get the data I want. but in a format I do not understand.
for example:
{
"build": BUILD NUMBER (integer),
"label": [
[
LABEL (string),
TORRENTS IN LABEL (integer)
],
...
],
"torrents": [
[
HASH (string),
STATUS* (integer),
NAME (string),
SIZE (integer in bytes),
PERCENT PROGRESS (integer in per mils),
DOWNLOADED (integer in bytes),
UPLOADED (integer in bytes),
RATIO (integer in per mils),
UPLOAD SPEED (integer in bytes per second),
DOWNLOAD SPEED (integer in bytes per second),
ETA (integer in seconds),
LABEL (string),
PEERS CONNECTED (integer),
PEERS IN SWARM (integer),
SEEDS CONNECTED (integer),
SEEDS IN SWARM (integer),
AVAILABILITY (integer in 1/65536ths),
TORRENT QUEUE ORDER (integer),
REMAINING (inte开发者_运维问答ger in bytes)
],
...
],
"torrentc": CACHE ID** (string integer)
}
torrent are like [a,b,c,d]. and each torrents are separeted by commas
so I end up with a file like this: [a,b,c,d],[a,b,c,d],[a,b,c,d]. I don't know if this structure has a name.
now, how can I transform that into something more readable like XML? thanks
It's JSON. You can find the spec and links to parsers for a big pile of languages at http://json.org/
It looks like the data is coming back as JSON, which is a simple and popular file-format for exchanging data on the web. You can use PHP's built-in json_decode
to parse it into PHP objects or PHP associative arrays.
mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
Takes a JSON encoded string and converts it into a PHP variable.
精彩评论