无法在 PHP 中从 Basecamp API 解析 SimpleXML
我正在使用 CodeIgniter 和为其编写的 Basecamp 类来连接到 Basecamp API 并从中检索数据。我正在正常连接并抓取数据,并且使用 SimpleXML 返回数据(您可以在请求中指定 XML 或 SimpleXML)。
我只是很难从回应中得到任何好的东西。以下是原始响应: http://pastie.org/private/bbxhgbzbbbk77ji3ua4g 并查看源代码:http://pastie.org/private/qftl28osnumhrdwr1zxuw
显然我通过 print_r 命令看到了这些。
例如,有人可以告诉我如何从中获取项目名称列表吗?
如果效果更好的话,我还可以用 XML 发出请求。
I'm using CodeIgniter and a Basecamp class written for it to connect to and retrieve data from the Basecamp API. I am connecting fine and grabbing data fine and its being returned using SimpleXML (you can specify XML or SimpleXML in the request).
I am just having a big problem getting anything good out of the response. Here is what the response looks like raw: http://pastie.org/private/bbxhgbzbbbk77ji3ua4g and view source: http://pastie.org/private/qftl28osnumhrdwr1zxuw
Obviously I see those via a print_r command.
Can someone tell me, for instance, how to get a list of the project names out of that?
I can also make the request in XML if that works better.
我们可以将响应中的“body”字符串加载到新的 SimpleXML 对象中,并迭代“project”节点以获取项目信息。在这里,您似乎已经加载了 SimpleXML 对象,因此我们只需要做剩下的事情即可。
干杯
We can load the 'body' string from the response into a new SimpleXML object and iterate over the 'project' nodes to get project information. Here it seems that you have already loaded the SimpleXML object, so we just have to do the rest.
cheers