Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

xml - Amazon Product Advertising API : How to get a JSON response for ItemLookup/Search

I'm trying to get the details of Amazon product from its ASIN. The product API allows to do a Itemlookup with ASIN, but the return value is in XML.

I want to do this call for Itemlookup from client side, so would like to do a JSONP call, which I couldn't find.

I found some articles on the web to convert the XML to JSON format using XSLT stylesheet:

(a) https://bitbucket.org/basti/python-amazon-product-api/src/tip/examples/json-results.py

I tried using this python-amazon-product-api and this example, but I couldn't get a JSON return.

(b) http://www.kokogiak.com/gedankengang/2006/05/consuming-amazons-web-api-directly.html

The request I tried to send is:

http://xml-us.amznxslt.com/onca/xml?AWSAccessKeyId=[ACCESS KEY]&AssociateTag=[ASSOCIATE TAG]&ContentType=text%2Fjavascript&IdType=ASIN&ItemId=B008IEGS9W&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes&Service=AWSECommerceService&Style=http%3A%2F%2Fforums.delphiforums.com%2Fdelphidocsz%2Famazon%2Fjson.xsl&Timestamp=2012-09-04T06%3A40%3A11Z&Signature=AGOqXvVSeMp3YyVkT4mGNXVx0cFGG%2Bh%2FdAebevbbF9o%3D

Please help with getting a JSON format with Amazon product API. Any suggestions are welcome.


The OP can run this style-sheet (input document not used) to determine his XSLT version.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="xsl msxsl">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <html>
    <head><title>About your XSLT Processor</title></head> 
   <body>
     <ul>
       <li>xsl:version=<xsl:value-of select="system-property('xsl:version')" /></li>
       <li>xsl:vendor=<xsl:value-of select="system-property('xsl:vendor')" /></li>
       <li>xsl:vendor-url=<xsl:value-of select="system-property('xsl:vendor-url')" /></li>
       <li>xsl:product-name=<xsl:value-of select="system-property('xsl:product-name')" /></li>
       <li>xsl:product-version=<xsl:value-of select="system-property('xsl:product-version')" /></li>
       <li>xsl:is-schema-aware=<xsl:value-of select="system-property('xsl:is-schema-aware')" /></li>
       <li>xsl:supports-serialization=<xsl:value-of select="system-property('xsl:supports-serialization')" /></li>
       <li>xsl:supports-backwards-compatibility=<xsl:value-of select="system-property('xsl:supports-backwards-compatibility')" /></li>
       <li>msxsl:version=<xsl:value-of select="system-property('msxsl:version')" /></li>
     </ul>  
   </body>  
 </html>  
</xsl:template>

</xsl:stylesheet>
question from:https://stackoverflow.com/questions/12258139/amazon-product-advertising-api-how-to-get-a-json-response-for-itemlookup-searc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try either of these ::

  1. Amazon JSON API - This is a ruby webservice to pass through requests and translate the responses to JSON.
  2. Try any of these Javascript functions to convert the XML you already have into JSON :
    1. http://goessner.net/download/prj/jsonxml/
    2. http://davidwalsh.name/convert-xml-json
    3. http://www.fyneworks.com/jquery/xml-to-json/
    4. http://www.thomasfrank.se/xml_to_json.html

I've tried thomasfrank myself. Its easy and works well :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...