【发布时间】:2017-03-13 04:52:02
【问题描述】:
我正在使用 Zoho CRM api,我能够在仅插入一个产品时提取产品 ID,但不知道如何处理多个产品。 https://www.zoho.com/crm/help/api/insertrecords.html#Insert_Multiple_records
我将响应转换为 simpleXMLElement,我可以通过以下方式轻松获得第一个产品 ID:
...curl stuff
$data = curl_exec($ch);
$xml = new SimpleXMLElement($data);
$product_id = $xml->result->recorddetail->FL[0];
问题是,如果我有多个产品 ID 被发回,我将如何在循环中获取每个产品 ID,因为我的代码只会成功返回第一个产品 ID。这是 api 中插入的 2 个产品的响应和返回响应的示例:
SimpleXMLElement Object ( [@attributes] => Array ( [uri] =>
/crm/private/xml/Products/insertRecords ) [result] => SimpleXMLElement
Object ( [message] => Record(s) added successfully [recorddetail] => Array (
[0] => SimpleXMLElement Object ( [FL] => Array ( [0] => **2389399000000122065**
[1] => 2017-03-12 21:33:50 [2] => 2017-03-12 21:33:50 [3] =>
SimpleXMLElement Object ( [@attributes] => Array ( [val] => Created By ) )
[4] => SimpleXMLElement Object ( [@attributes] => Array ( [val] => Modified
By ) ) ) ) [1] => SimpleXMLElement Object ( [FL] => Array ( [0] =>
**2389399000000122066** [1] => 2017-03-12 21:33:50 [2] => 2017-03-12 21:33:50
[3] => SimpleXMLElement Object ( [@attributes] => Array ( [val] => Created
By ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [val] =>
Modified By ) ) ) ) ) ) )
不确定它是否以粗体显示,但 ** ** 中的两个值是我要提取的。
【问题讨论】:
-
在这样的问题中,最好展示一个实际 XML 的示例,而不是 SimpleXML,因为
print_r/var_dump不能很好地处理 SimpleXML,而且任何人都不能从 XML可以重现您的代码以检查他们的解决方案。
标签: php object simplexml crm zoho