sách gpt4 ai đã đi

php - 您如何解析 MWS GetMatchingProduct 中的关系?

In lại 作者:可可西里 更新时间:2023-11-01 12:17:10 28 4
mua khóa gpt4 Nike

数据:





ATVPDKIKX0DER
B002KT3XQC


Black
Small




ATVPDKIKX0DER
B002KT3XQW


Black
Medium


Mã số:

$data = simplexml_load_string($response);
foreach($data->GetMatchingProductResult AS $GetMatchingProductResult){
$Product = $GetMatchingProductResult->Product;
$Relationships = $Product->Relationships;

foreach($Relationships->children('ns2', true)->VariationChild AS $VariationChild){

$Identifiers = $VariationChild->Identifiers;
$MarketplaceASIN = $Identifiers->MarketplaceASIN;
$MarketplaceId = $MarketplaceASIN->MarketplaceId;
$ASIN = $MarketplaceASIN->ASIN;

echo "$ASIN
";

}
}

这与返回相呼应,但没有数据,因此它实际上是在 XML 中循环。然而,我尝试的任何事情实际上都不会在 $ASIN 变量中返回数据。这是因为 namespace 或 simpleXML,还是我完全遗漏了其他东西?

编辑:尝试了其他方法

foreach($Relationships->children('http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd', true)->VariationChild AS $VariationChild){

$Identifiers = $VariationChild->Identifiers;
$MarketplaceASIN = $Identifiers->MarketplaceASIN;
$MarketplaceId = $MarketplaceASIN->MarketplaceId;
$ASIN = $MarketplaceASIN->ASIN;

echo "[$ASIN]
";

}

$test = new SimpleXMLElement($response);
$test->registerXPathNamespace('ns2', 'http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd');
$variations = $test->xpath('//ns2:VariationChild');

foreach($variations AS $vars){

print_r($vars);

}

似乎都没有循环数据。

1 Câu trả lời

以下代码获取 ASIN 字符串:

$data = simplexml_load_string($response);

foreach ($data->GetMatchingProductResult as $GetMatchingProductResult) {
$Product = $GetMatchingProductResult->Product;
$Relationships = $Product->Relationships;

foreach ($Relationships->children('ns2', true)->VariationChild
as $VariationChild)
{
foreach ($VariationChild->children('', true) as $var_child) {
echo $var_child->MarketplaceASIN->ASIN, PHP_EOL;
}
}
}

值得一提的是,real response format与您发布的内容不同。

关于php - 您如何解析 MWS GetMatchingProduct 中的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39583983/

28 4 0
可可西里
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com