1

我从 XML 响应中获取标准元素没有任何问题,getChild('BuyerEmail', NS).getText()但是如果最后有这样的额外数据,getChild('ItemCost currencyID="GBP"', NS).getValue()那么我的代码会因 NUL 而失败。它似乎是 currencyID="GBP"哪个问题?!?!

我究竟做错了什么?

代码片段:

  var document = XmlService.parse(response);
  var root = document.getRootElement();
  var NS = XmlService.getNamespace("urn:ebay:apis:eBLBaseComponents");
   
  var ack = root.getChildText('Ack', NS);
  var time = root.getChildText('Timestamp', NS);
  var version = root.getChildText('Version', NS);
  var build = root.getChildText('Build', NS);
  var shortmessage = root.getChildText('ShortMessage', NS);
  var longmessage = root.getChildText('LongMessage', NS);
 
  var sr = root.getChildren('SaleRecord', NS);    
  
  for (var i = 0; i < sr.length; i++) {
      
    var orderids = sr[i].getChildren('SellingManagerSoldTransaction', NS);
    
    for (var L = 0; L < orderids.length; L++) {      
     
    var srn = orderids[L].getChild('SaleRecordID', NS).getText();

    var sku = orderids[L].getChild('CustomLabel', NS).getText();
      
    var title = orderids[L].getChild('ItemTitle', NS).getText();

    var qty = orderids[L].getChild('QuantitySold', NS).getText();  
        
    var lineitem = orderids[L].getChild('OrderLineItemID', NS).getText();    
   
    var name = sr[i].getChild('ShippingAddress', NS).getChild('Name', NS).getText();
    var pcode = sr[i].getChild('ShippingAddress', NS).getChild('PostalCode', NS).getText();
    var status = sr[i].getChild('OrderStatus', NS).getChild('CheckoutStatus', NS).getText();
    var paidtime = sr[i].getChild('OrderStatus', NS).getChild('PaidTime', NS).getText();
    var shipped = sr[i].getChild('OrderStatus', NS).getChild('ShippedStatus', NS).getText();
    var email = sr[i].getChild('BuyerEmail', NS).getText();
    var price = sr[i].getChild('SalePrice', NS).getValue();
    var totprice = sr[i].getChild('TotalAmount', NS).getValue();
    
    sheet.appendRow([srn, sku, title, qty, price, totprice, lineitem, name, pcode, status, paidtime, shipped, email]);
      
      }

XML 响应示例:

<?xml version="1.0" encoding="utf-8"?>
<GetSellingManagerSoldListingsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <!-- Call-specific Output Fields -->
  <PaginationResult> PaginationResultType
    <TotalNumberOfEntries> int </TotalNumberOfEntries>
    <TotalNumberOfPages> int </TotalNumberOfPages>
  </PaginationResult>
  <SaleRecord> SellingManagerSoldOrderType
    <BuyerEmail> string </BuyerEmail>
    <BuyerID> string </BuyerID>
    <CashOnDeliveryCost currencyID="CurrencyCodeType"> AmountType (double) </CashOnDeliveryCost>
    <CreationTime> dateTime </CreationTime>
    <DaysSinceSale> int </DaysSinceSale>
    <ItemCost currencyID="CurrencyCodeType"> AmountType (double) </ItemCost>
    <OrderStatus> SellingManagerOrderStatusType
      <CheckoutStatus> CheckoutStatusCodeType </CheckoutStatus>
      <FeedbackReceived> CommentTypeCodeType </FeedbackReceived>
      <FeedbackSent> boolean </FeedbackSent>
      <IntegratedMerchantCreditCardEnabled> boolean </IntegratedMerchantCreditCardEnabled>
      <PaidStatus> SellingManagerPaidStatusCodeType </PaidStatus>
      <PaidTime> dateTime </PaidTime>
      <PaymentHoldStatus> PaymentHoldStatusCodeType </PaymentHoldStatus>
      <PaymentMethodUsed> BuyerPaymentMethodCodeType </PaymentMethodUsed>
      <ShippedStatus> SellingManagerShippedStatusCodeType </ShippedStatus>
      <ShippedTime> dateTime </ShippedTime>
      <TotalEmailsSent> int </TotalEmailsSent>
    </OrderStatus>
    <SalePrice currencyID="CurrencyCodeType"> AmountType (double) </SalePrice>
    <SaleRecordID> long </SaleRecordID>
    <SellingManagerSoldTransaction> SellingManagerSoldTransactionType
      <CharityListing> boolean </CharityListing>
      <CustomLabel> string </CustomLabel>
      <ItemID> ItemIDType (string) </ItemID>
      <ItemTitle> string </ItemTitle>
      <ListedOn> TransactionPlatformCodeType </ListedOn>
      <!-- ... more ListedOn values allowed here ... -->
      <ListingType> ListingTypeCodeType </ListingType>
      <OrderLineItemID> string </OrderLineItemID>
      <QuantitySold> int </QuantitySold>
      <Relisted> boolean </Relisted>
      <ReservePrice currencyID="CurrencyCodeType"> AmountType (double) </ReservePrice>
      <SaleRecordID> long </SaleRecordID>
      <SecondChanceOfferSent> boolean </SecondChanceOfferSent>
      <SoldOn> TransactionPlatformCodeType </SoldOn>
      <StartPrice currencyID="CurrencyCodeType"> AmountType (double) </StartPrice>
      <TransactionID> long </TransactionID>
      <Variation> VariationType </Variation>
      <WatchCount> int </WatchCount>
    </SellingManagerSoldTransaction>
    <!-- ... more SellingManagerSoldTransaction nodes allowed here ... -->
    <ShippingAddress> AddressType
      <Name> string </Name>
      <PostalCode> string </PostalCode>
    </ShippingAddress>
    <ShippingDetails> ShippingDetailsType
      <ShippingType> ShippingTypeCodeType </ShippingType>
    </ShippingDetails>
    <TotalAmount currencyID="CurrencyCodeType"> AmountType (double) </TotalAmount>
    <TotalQuantity> int </TotalQuantity>
    <UnpaidItemStatus> UnpaidItemStatusTypeCodeType </UnpaidItemStatus>
  </SaleRecord>
  <!-- ... more SaleRecord nodes allowed here ... -->
  <!-- Standard Output Fields -->
  <Ack> AckCodeType </Ack>
  <Build> string </Build>
  <CorrelationID> string </CorrelationID>
  <Errors> ErrorType
    <ErrorClassification> ErrorClassificationCodeType </ErrorClassification>
    <ErrorCode> token </ErrorCode>
    <ErrorParameters ParamID="string"> ErrorParameterType
      <Value> string </Value>
    </ErrorParameters>
    <!-- ... more ErrorParameters nodes allowed here ... -->
    <LongMessage> string </LongMessage>
    <SeverityCode> SeverityCodeType </SeverityCode>
    <ShortMessage> string </ShortMessage>
  </Errors>
  <!-- ... more Errors nodes allowed here ... -->
  <HardExpirationWarning> string </HardExpirationWarning>
  <Timestamp> dateTime </Timestamp>
  <Version> string </Version>
</GetSellingManagerSoldListingsResponse>

4

1 回答 1

0

我发现我可以只使用:ItemCost、SalePrice 和 TotalAmount 而不使用currencyID="GBP". 我错过了这个,因为 ItemCost 在有或没有currencyID="GBP". 两个都

于 2020-10-06T20:24:38.370 回答