2014-03-30 140 views
0

嗨,大家好,我有麻烦从亚马逊web api获取产品。亚马逊产品广告c#api

我从互联网上使用了这段代码,添加了所有必要的引用。我尝试添加一个视图,并选择itemsearchresponce作为模型类,但它并没有显示产品,我得到以下错误:

Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'AmazonProduct.com.amazon.webservices.ImageSet' to 'AmazonProduct.com.amazon.webservices.ImageSet[]'

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

using AmazonProduct.com.amazon.webservices; 
namespace Forest.Controllers 
{ 
    public class AmazonController : Controller 
    { 
     private AmazonProduct.com.amazon.webservices.AWSECommerceService _Products; 

     public AmazonController() 
     { 
      _Products = new AmazonProduct.com.amazon.webservices.AWSECommerceService(); 
     } 

     [HttpGet] 
     public ActionResult listProducts() 
     { 
      var searchIndex = "Shoes"; 
      var keywords = "jordan"; 
      // Create an ItemSearch wrapper 
      ItemSearch search = new ItemSearch(); 
      search.AssociateTag = "[Your Associate ID]"; 
      search.AWSAccessKeyId = "MyKey"; 
      // search.Version= "2011-08-01"; 

      // Create a request object 
      ItemSearchRequest request = new ItemSearchRequest(); 

      // Fill the request object with request parameters 
      request.ResponseGroup = new string[] { "ItemAttributes" }; 

      // Set SearchIndex and Keywords 
      request.SearchIndex = searchIndex; 
      request.Keywords = keywords; 

      // Set the request on the search wrapper 
      search.Request = new ItemSearchRequest[] { request }; 

      ItemSearchResponse response = _Products.ItemSearch(search); 

      return View(response); 
     } 
    } 
} 
+0

由于您只是将结果返回给视图,因此错误很可能发生在使用ImageSet的视图中。该错误似乎表明您的结果实际上是一个ImageSet [](ImageSet对象数组),而您的代码中的某处(而不是您发布的代码)您试图将该结果视为单个ImageSet。找到那个地方,你会发现问题。或发布相关的查看代码以获得进一步的帮助。 –

回答