使用 PHP 解析内容
我正在尝试使用 uTorrent webUI API。我认为这是一个非常棘手的问题,但抱歉,网上关于此 API 的文档很少。
我的服务器使用 file_get_contents($url) 我得到了我想要的数据。但格式我不明白。
例如:
{
"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 (integer in bytes)
],
...
],
"torrentc": CACHE ID** (string integer)
}
torrent 类似于 [a,b,c,d]。每个种子都用逗号分隔
,所以我最终得到一个这样的文件:[a,b,c,d],[a,b,c,d],[a,b,c,d]。我不知道这个结构是否有名字。
现在,我怎样才能将其转换为更具可读性的内容,例如 XML? 谢谢
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 (integer 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 JSON。您可以在 http://json.org/ 找到大量语言的规范和解析器链接
It's JSON. You can find the spec and links to parsers for a big pile of languages at http://json.org/
看起来数据以 JSON 的形式返回,这是一种简单且流行的文件格式,用于在网络上交换数据。您可以使用 PHP 内置的
json_decode
将其解析为 PHP 对象或 PHP 关联数组。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.