使用 PHP 解析内容

发布于 2024-09-29 19:46:42 字数 1352 浏览 8 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-10-06 19:46:42

这是 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/

迷你仙 2024-10-06 19:46:42

看起来数据以 JSON 的形式返回,这是一种简单且流行的文件格式,用于在网络上交换数据。您可以使用 PHP 内置的 json_decode 将其解析为 PHP 对象或 PHP 关联数组。

混合 json_decode ( string $json [, bool $assoc = false [, int $深度 =
第512章

获取 JSON 编码字符串并将其转换
到 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文