2017-03-13 10 views
0

Zoho CRM API를 사용하여 하나의 제품 만 삽입 할 때 제품 ID를 추출 할 수 있었지만 여러 제품을 사용하여 제품 ID를 추출 할 수 없었습니다. https://www.zoho.com/crm/help/api/insertrecords.html#Insert_Multiple_recordsZoho CRM API simpleXMLelement 여러 제품 ID 가져 오기

나는 simpleXMLElement에 대한 응답을 변환하고 나는 쉽게 첫 번째 제품 ID를 얻을 수 있습니다 :

나는 경우
...curl stuff 
$data = curl_exec($ch); 
$xml = new SimpleXMLElement($data); 
$product_id = $xml->result->recorddetail->FL[0]; 

문제는 여러 제품 ID의 내가 루프 등의 각 하나 얻을 것 어떻게 다시 전송 내 코드는 첫 번째 제품 ID 만 성공적으로 반환합니다. 이 굵은 글씨로 표시되지만 ** ** 안에 두 값이 I가 무엇을 찾고있는 경우

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))))))) 

확실하지 :이 2 개 API에 삽입 된 제품과 반환 된 응답의 응답의 예입니다 추출물.

$xml->result->recorddetail->FL[0]; 

이 단지 속기 :이의 핵심은이 것을 이해하는 것입니다

+0

, 그것은 오히려 SimpleXML을보다 실제 XML의 샘플을 보여하는 것이 가장 좋습니다 SimpleXML에 매우 잘 대처할 수 있으며 XML을 통해 누구나 자신의 솔루션을 확인할 수있는 코드를 재현 할 수 있습니다. – IMSoP

답변

1

은 분명 2 recorddetail (와 인덱스 1)에 액세스 할 수 있는지 확인해야

$xml->result[0]->recorddetail[0]->FL[0]; 

쓸 수 있습니다.

$xml->result->recorddetail[1]->FL[0]; 

그들에

귀하의 경우에 가장 관련되게
count($xml->result->recorddetail); 

그리고, 루프 : 마지막 팁으로

foreach ($xml->result->recorddetail as $recorddetail) { 
    $product_id = $recorddetail->FL[0]; 
} 

, 당신은 아마도 $product_id 변수를 원하는 마법 SimpleXML을 당신은 또한 얼마나 많은 알 수 있습니다 제공 SimpleXML 객체가 아닌 일반 문자열을 유지합니다. 이처럼 "문자열 캐스트"와 것을 얻을 : print_r` /`var_dump`하지 않는`때문에이 같은 질문에

$product_id = (string)$recorddetail->FL[0]; 
+0

IMSoP 솔루션은 귀하의 상세한 설명을 통해 완벽하게 이해할 수있게되었습니다. –