【问题标题】:How to parse curl to JSON?如何将 curl 解析为 JSON?
【发布时间】:2017-09-08 16:22:36
【问题描述】:

我是使用 curl 的新手,我不知道如何将此链接解析为 JSON:

    curl --get --include 'https://doodle-manga-
    scraper.p.mashape.com/mangafox.me/manga/naruto/1' \
    -H 'X-Mashape-Key: LhdkCyyF6Tmsh3BXTnN79quTbg08p1j2B20jsn89wOXridOzNe' \
     -H 'Accept: text/plain'

我确实有这个 PHP 脚本:

     $curl = curl_init();
    curl_setopt_array($curl, array(
     CURLOPT_RETURNTRANSFER => 1,
       CURLOPT_URL => 'https://doodle-manga-
    scraper.p.mashape.com/mangafox.me/manga/naruto/1'
        ));

我从未使用过 curl。如何使用 PHP 解析上述命令中的数据?

【问题讨论】:

  • 欢迎来到 Stack Overflow!我们是一个志愿者社区,为陷入特定任务的程序员提供帮助。我们不是为您编写免费代码的服务。请阅读What topics can I ask about here?How do I ask a good question?
  • @AlexHowansky,我很抱歉,我知道这一点。我实际上是一名信息学学生,我真的不知道该怎么做。我知道堆栈溢出!我们是一个志愿者社区,为陷入特定任务的程序员提供帮助。但我真的坚持这一点,

标签: php json curl


【解决方案1】:

我们正在讨论解析响应,是吗?您需要安装 python,但这对我有用:

| python -m json.tool

把它放在你的陈述的末尾。所以你的看起来像:

curl --get --include 'https://doodle-manga-
scraper.p.mashape.com/mangafox.me/manga/naruto/1' \
-H 'X-Mashape-Key: LhdkCyyF6Tmsh3BXTnN79quTbg08p1j2B20jsn89wOXridOzNe' \
 -H 'Accept: text/plain' | python -m json.tool

【讨论】:

  • 实际上我正在尝试纠正一个解析来自此 curl 命令的数据的 php 脚本。我真的不明白 curl 的东西,我需要在明天之后完成这件事:(。
【解决方案2】:
  $post = array('X-Mashape-Key' =>'LhdkCyyF6Tmsh3BXTnN79quTbg08p1j2B20jsn89wOXridOzNe' , 'Accept' => 'text/plain');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://doodle-manga-scraper.p.mashape.com/mangafox.me/manga/naruto/1');
        curl_setopt($ch, CURLOPT_POST, True);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

        $result = curl_exec($ch);
        $jsonresult = json_decode($result);

应该是这样的

【讨论】:

    猜你喜欢
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多