【问题标题】:Google Adwords API Report Utilities - PHP - Invalid XML?Google Adwords API 报告实用程序 - PHP - XML 无效?
【发布时间】:2016-02-28 15:45:21
【问题描述】:

我使用 PHP 获得了 AdWords API,我正在测试其中的一些功能。一个功能是通过 AWQL 生成报告。因此,一切正常,但是当我尝试解析 Xml 并尝试将其转换为 json 时,会发生一些奇怪的错误。我正在使用以下代码:

DownloadCriteriaReportWithAwqlExample($user, $filePath, $reportFormat);

$xml = simplexml_load_string($filePath);
$json = json_encode($xml);
$array = json_decode($json, true);

我收到有关以下代码行的此错误:

$xml = simplexml_load_string($filePath);

警告:simplexml_load_string():实体:第 1 行:解析器错误:开始 应有标记,在 C:\PHP\Optima\adwords-examples-and-lib- 中找不到“

Xml 看起来格式正确。有没有人遇到过这个错误并且知道问题是什么?感谢您提供任何信息。

【问题讨论】:

    标签: php xml report google-ads-api


    【解决方案1】:

    你会踢自己...

    simplexml_load_string() 需要一个 string 而不是文件的路径。要么先将文件读入字符串,要么使用simplexml_load_file()。

     $xml = simplexml_load_file($filePath);
     $json = json_encode($xml);
    

    【讨论】:

    • 哎呀。尴尬。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多