我正在尝试使用他们的产品API在amazon.com上获取产品的信息。
有2页。第一页将包含ASIN代码的文件上传到另一个页面,并使用malsup jquery表单插件执行此操作。另一个页面使用API来获取响应并使用php json_encode函数将其转换为json并返回到第一页。
第一页:
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
$(document).ready(function()
{
var options = {
beforeSend: function()
{
$("#progress").show();
//clear everything
$("#progress").width('0%');
$("#progress").text('0%');
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#progress").css('width',percentComplete+'%');
$("#progress").text(percentComplete+'%');
},
success: function()
{
$("#progress").width('100%');
$("#progress").text('0%');
},
complete: function(response)
{
var restext = response.responseText;
var links = JSON.parse(restext);
console.log(JSON.parse(links));
$("#message").html("<font color='green'>"+links[0]+"</font>");
// alert(links[1].Items.Item.DetailPageURL);
links.forEach(function(link){
alert(link.Items.Item.ASIN);
var results = link.Items.Item.ItemLinks.ItemLink; //array
results.forEach(function(result){
$("#description").append("<h3 color='green'>"+result.Description+"</h3> \n<a href='"+result.URL+"'>"+result.URL+"</a>");
// $("#URLS").append("<p color='green'>"+result.URL+"</p>");
});
alert()
$("#ASIN").append("<p color='green'>"+link.Items.Item.ASIN+"</p>");
$('#mainurltext').show();
$("#mainurl").append("<a href='"+link.Items.Item.DetailPageURL+"'>"+link.Items.Item.DetailPageURL+"</a>");
$("#image").append("<img src='"+link.Items.Item.LargeImage.URL+"' width='375' height-'500' />");
});
// $("#message").html("<font color='green'>"+result[0].URL+"</font>");
},
error: function()
{
$("#message").html("<font color='red'> ERROR: unable to upload files</font>");
},
dataType: "json",
}
$("#productform").ajaxForm(options);
});
</script>
第二页使用api并返回JSON:
<?php
require_once "vendor/autoload.php";
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Search;
use ApaiIO\ApaiIO;
use ApaiIO\Operations\Lookup;
function scrape($info)
{
$conf = new GenericConfiguration();
$conf
->setCountry('com')
->setAccessKey("API KEY")
->setSecretKey('API SECRET')
->setAssociateTag('ASSOCIATE TAG');
$apaiIo = new ApaiIO($conf);
$lookup = new Lookup();
$lookup->setItemId($info); //B00D6BN9NK
$lookup->setResponseGroup(array('Large')); // More detailed information
$response = $apaiIo->runOperation($lookup);
$xml = simplexml_load_string($response) or die('Cannot create xml element');
$json = json_encode($xml);
return $json;
}
if(isset($_POST['submit']))
{
if(isset($_FILES['infofile']))
{
if($_FILES['infofile']['error'] > 0)
{
echo "<pre>Error ". $_FILES['infofile']['error'] . " </pre>";
}else{
move_uploaded_file($_FILES['infofile']['tmp_name'], "uploads/".$_FILES['infofile']['name']);
}
}
$lines = file("uploads/".$_FILES['infofile']['name'],FILE_IGNORE_NEW_LINES);
$items = "";
foreach($lines as $line)
{
$items .= scrape($line) . ",";
}
$items = rtrim($items,",");
$items = "[".$items."]";
echo json_encode($items);
}
但问题是我无法解析json。当我使用var json = JSON.parse(response.responseText)和console.log(json [0]);它记录第一个字符而不是第一个字符。
Console..log(json)正在输出:
[{"OperationRequest":{"HTTPHeaders":{"0":{"@attributes":{"Name":"UserAgent","Value":"ApaiIO [2.0.0-DEV]"}}},"RequestId":"7a5bf557-5b04-4685-be67-094c970bdf8b","Arguments":{"Argument":[{"@attributes":{"Name":"AWSAccessKeyId","Value":"AKIAIBYRBZRR7WVI3CMQ"}},{"@attributes":{"Name":"AssociateTag","Value":"heyadme-20"}},{"@attributes":{"Name":"ItemId","Value":"B00D6BN9NK"}},{"@attributes":{"Name":"Operation","Value":"ItemLookup"}},{"@attributes":{"Name":"ResponseGroup","Value":"Large"}},{"@attributes":{"Name":"Service","Value":"AWSECommerceService"}},{"@attributes":{"Name":"Timestamp","Value":"2015-10-02T18:30:08Z"}},{"@attributes":{"Name":"Version","Value":"2011-08-01"}},{"@attributes":{"Name":"Signature","Value":"ilDCR1xAoQLM8cUAixQUt\/0z5QoWDJqL2LUtD5cDB2g="}}]},"RequestProcessingTime":"0.0874180000000000"},"Items":{"Request":{"IsValid":"True","ItemLookupRequest":{"IdType":"ASIN","ItemId":"B00D6BN9NK","ResponseGroup":"Large","VariationPage":"All"}},"Item":{"ASIN":"B00D6BN9NK","DetailPageURL":"http:\/\/www.amazon.com\/A-Good-Day-Die-Hard\/dp\/B00D6BN9NK%3FSubscriptionId%3DAKIA…nkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00D6BN9NK","ItemLinks":{"ItemLink":[{"Description":"Technical Details","URL":"http:\/\/www.amazon.com\/A-Good-Day-Die-Hard\/dp\/tech-data\/B00D6BN9NK%3FSubscripti…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"Add To Baby Registry","URL":"http:\/\/www.amazon.com\/gp\/registry\/baby\/add-item.html%3Fasin.0%3DB00D6BN9NK%26S…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"Add To Wedding Registry","URL":"http:\/\/www.amazon.com\/gp\/registry\/wedding\/add-item.html%3Fasin.0%3DB00D6BN9NK%…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"Add To Wishlist","URL":"http:\/\/www.amazon.com\/gp\/registry\/wishlist\/add-item.html%3Fasin.0%3DB00D6BN9NK…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"Tell A Friend","URL":"http:\/\/www.amazon.com\/gp\/pdp\/taf\/B00D6BN9NK%3FSubscriptionId%3DAKIAIBYRBZRR7WV…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"All Customer Reviews","URL":"http:\/\/www.amazon.com\/review\/product\/B00D6BN9NK%3FSubscriptionId%3DAKIAIBYRBZRR…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"},{"Description":"All Offers","URL":"http:\/\/www.amazon.com\/gp\/offer-listing\/B00D6BN9NK%3FSubscriptionId%3DAKIAIBYRBZ…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK"}]},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL75_.jpg","Height":"75","Width":"56"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL160_.jpg","Height":"160","Width":"120"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL.jpg","Height":"500","Width":"375"},"ImageSets":{"ImageSet":{"@attributes":{"Category":"primary"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL30_.jpg","Height":"30","Width":"22"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL75_.jpg","Height":"75","Width":"56"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL75_.jpg","Height":"75","Width":"56"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL110_.jpg","Height":"110","Width":"82"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL._SL160_.jpg","Height":"160","Width":"120"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51TOcIFX%2BVL.jpg","Height":"500","Width":"375"}}},"ItemAttributes":{"Actor":["Bruce Willis","Jai Courtney","Sebastian Koch","Rasha Bukvic","Cole Hauser"],"AudienceRating":"R (Restricted)","Binding":"Amazon Instant Video","Director":"John Moore","Genre":"Action","Languages":{"Language":[{"Name":"English","Type":"Subtitled"},{"Name":"English","Type":"Unknown"}]},"ProductGroup":"Movie","ProductTypeName":"DOWNLOADABLE_MOVIE","ReleaseDate":"2015-09-11","RunningTime":"98","Studio":"Fox","Title":"A Good Day to Die Hard"},"OfferSummary":{"LowestNewPrice":{"Amount":"299","CurrencyCode":"USD","FormattedPrice":"$2.99"},"TotalNew":"1","TotalUsed":"0","TotalCollectible":"0","TotalRefurbished":"0"},"Offers":{"TotalOffers":"1","TotalOfferPages":"1","MoreOffersUrl":"http:\/\/www.amazon.com\/gp\/offer-listing\/B00D6BN9NK%3FSubscriptionId%3DAKIAIBYRBZ…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00D6BN9NK","Offer":{"OfferAttributes":{"Condition":"New"},"OfferListing":{"OfferListingId":"jz9ClzBQvnwulA5JO%2FG01g%2BOlezQ77ZsP3jCkxm3Hz8Xah%2Bpk7Vq%2FhLk5d6cfXJYdZqaOo%2FX3lGnrsrt54DkqQdYwuYSwALKXpzsC9wgDCH5mKMozevD4hmIPlMaJjNkN%2Bm11nUqRDFydPEIfcYFyN5EW01GQ7to","Price":{"Amount":"299","CurrencyCode":"USD","FormattedPrice":"$2.99"},"Availability":"Usually ships in 1-2 business days","AvailabilityAttributes":{"AvailabilityType":"now","MinimumHours":"24","MaximumHours":"48"},"IsEligibleForSuperSaverShipping":"0","IsEligibleForPrime":"0"}}},"CustomerReviews":{"IFrameURL":"http:\/\/www.amazon.com\/reviews\/iframe?akid=AKIAIBYRBZRR7WVI3CMQ&alinkCode=xm2&asi…-03T06%3A00%3A21Z&v=2&sig=HGZbLdRlswUpuZj3i%2FPqUa0EyuV90Mb990WGO9xtn4A%3D","HasReviews":"true"},"SimilarProducts":{"SimilarProduct":[{"ASIN":"B0011MZOEI","Title":"Live Free or Die Hard"},{"ASIN":"B00AGDX2F6","Title":"Die Hard 2: Die Harder"},{"ASIN":"B001FVD65O","Title":"Die Hard: With a Vengeance"},{"ASIN":"B004Z1IKCK","Title":"Die Hard: With a Vengeance"},{"ASIN":"B000SZK41M","Title":"Die Hard"}]},"BrowseNodes":{"BrowseNode":[{"BrowseNodeId":"2649512011","Name":"Movies","Ancestors":{"BrowseNode":{"BrowseNodeId":"2625374011","Name":"Departments","IsCategoryRoot":"1","Ancestors":{"BrowseNode":{"BrowseNodeId":"2625373011","Name":"Movies & TV"}}}}},{"BrowseNodeId":"2858905011","Name":"Movies","Ancestors":{"BrowseNode":{"BrowseNodeId":"2858778011","Name":"Amazon Video","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644982011","Name":"Custom Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644981011","Name":"Specialty Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2625373011","Name":"Movies & TV"}}}}}}}}},{"BrowseNodeId":"2958762011","Name":"Action & Adventure","Ancestors":{"BrowseNode":{"BrowseNodeId":"2958761011","Name":"Genre for Featured Categories","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644982011","Name":"Custom Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644981011","Name":"Specialty Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2625373011","Name":"Movies & TV"}}}}}}}}},{"BrowseNodeId":"277825011","Name":"Compatible Devices","Ancestors":{"BrowseNode":{"BrowseNodeId":"2998370011","Name":"AIV Custom Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644982011","Name":"Custom Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2644981011","Name":"Specialty Stores","Ancestors":{"BrowseNode":{"BrowseNodeId":"2625373011","Name":"Movies & TV"}}}}}}}}}]}}}},{"OperationRequest":{"HTTPHeaders":{"0":{"@attributes":{"Name":"UserAgent","Value":"ApaiIO [2.0.0-DEV]"}}},"RequestId":"028a0fc0-c52e-4d19-b831-c1337aff724e","Arguments":{"Argument":[{"@attributes":{"Name":"AWSAccessKeyId","Value":"AKIAIBYRBZRR7WVI3CMQ"}},{"@attributes":{"Name":"AssociateTag","Value":"heyadme-20"}},{"@attributes":{"Name":"ItemId","Value":"B00CCHBA8U"}},{"@attributes":{"Name":"Operation","Value":"ItemLookup"}},{"@attributes":{"Name":"ResponseGroup","Value":"Large"}},{"@attributes":{"Name":"Service","Value":"AWSECommerceService"}},{"@attributes":{"Name":"Timestamp","Value":"2015-10-02T18:30:09Z"}},{"@attributes":{"Name":"Version","Value":"2011-08-01"}},{"@attributes":{"Name":"Signature","Value":"4tT70GT20eszPG6BbOUgbJZnJFr66wgLRr\/A4ttX2Cw="}}]},"RequestProcessingTime":"0.0287780000000000"},"Items":{"Request":{"IsValid":"True","ItemLookupRequest":{"IdType":"ASIN","ItemId":"B00CCHBA8U","ResponseGroup":"Large","VariationPage":"All"}},"Item":{"ASIN":"B00CCHBA8U","DetailPageURL":"http:\/\/www.amazon.com\/SHEER-NO2-Supplement-Top-Rated-Guarantee\/dp\/B00CCHBA8U%3F…nkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00CCHBA8U","ItemLinks":{"ItemLink":[{"Description":"Technical Details","URL":"http:\/\/www.amazon.com\/SHEER-NO2-Supplement-Top-Rated-Guarantee\/dp\/tech-data\/B0…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"Add To Baby Registry","URL":"http:\/\/www.amazon.com\/gp\/registry\/baby\/add-item.html%3Fasin.0%3DB00CCHBA8U%26S…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"Add To Wedding Registry","URL":"http:\/\/www.amazon.com\/gp\/registry\/wedding\/add-item.html%3Fasin.0%3DB00CCHBA8U%…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"Add To Wishlist","URL":"http:\/\/www.amazon.com\/gp\/registry\/wishlist\/add-item.html%3Fasin.0%3DB00CCHBA8U…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"Tell A Friend","URL":"http:\/\/www.amazon.com\/gp\/pdp\/taf\/B00CCHBA8U%3FSubscriptionId%3DAKIAIBYRBZRR7WV…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"All Customer Reviews","URL":"http:\/\/www.amazon.com\/review\/product\/B00CCHBA8U%3FSubscriptionId%3DAKIAIBYRBZRR…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"},{"Description":"All Offers","URL":"http:\/\/www.amazon.com\/gp\/offer-listing\/B00CCHBA8U%3FSubscriptionId%3DAKIAIBYRBZ…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U"}]},"SalesRank":"533","SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL75_.jpg","Height":"75","Width":"75"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL160_.jpg","Height":"160","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL.jpg","Height":"500","Width":"500"},"ImageSets":{"ImageSet":[{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL._SL30_.jpg","Height":"23","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL._SL75_.jpg","Height":"57","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL._SL75_.jpg","Height":"57","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL._SL110_.jpg","Height":"84","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL._SL160_.jpg","Height":"122","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41h8knclZoL.jpg","Height":"380","Width":"500"}},{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL._SL30_.jpg","Height":"23","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL._SL75_.jpg","Height":"57","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL._SL75_.jpg","Height":"57","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL._SL110_.jpg","Height":"84","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL._SL160_.jpg","Height":"122","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/412Kz4g-JXL.jpg","Height":"380","Width":"500"}},{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL._SL30_.jpg","Height":"23","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL._SL75_.jpg","Height":"57","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL._SL75_.jpg","Height":"57","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL._SL110_.jpg","Height":"84","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL._SL160_.jpg","Height":"122","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/41F-sRusupL.jpg","Height":"380","Width":"500"}},{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL._SL30_.jpg","Height":"30","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL._SL75_.jpg","Height":"75","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL._SL75_.jpg","Height":"75","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL._SL110_.jpg","Height":"110","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL._SL160_.jpg","Height":"160","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Ljcas4ikL.jpg","Height":"500","Width":"500"}},{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL._SL30_.jpg","Height":"30","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL._SL75_.jpg","Height":"75","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL._SL75_.jpg","Height":"75","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL._SL110_.jpg","Height":"110","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL._SL160_.jpg","Height":"160","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61vZGtnnSiL.jpg","Height":"500","Width":"500"}},{"@attributes":{"Category":"variant"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL._SL30_.jpg","Height":"30","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL._SL75_.jpg","Height":"75","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL._SL75_.jpg","Height":"75","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL._SL110_.jpg","Height":"110","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL._SL160_.jpg","Height":"160","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/61Fqhz0C6SL.jpg","Height":"500","Width":"500"}},{"@attributes":{"Category":"primary"},"SwatchImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL30_.jpg","Height":"30","Width":"30"},"SmallImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL75_.jpg","Height":"75","Width":"75"},"ThumbnailImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL75_.jpg","Height":"75","Width":"75"},"TinyImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL110_.jpg","Height":"110","Width":"110"},"MediumImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL._SL160_.jpg","Height":"160","Width":"160"},"LargeImage":{"URL":"http:\/\/ecx.images-amazon.com\/images\/I\/51t-yqnE3sL.jpg","Height":"500","Width":"500"}}]},"ItemAttributes":{"Binding":"Health and Beauty","Brand":"Sheer Strength Labs","EAN":"0820103175005","EANList":{"EANListElement":"0820103175005"},"Feature":["BUILD MUSCLE AND STRENGTH OR YOUR MONEY BACK! When Taken With A Good Workout Plan, Sheer Strength NO2 Is GUARANTEED To Increase Muscle Growth And Strength Or Your Money Back! You'll Feel It Kicking In And Adding Strength To Your Workouts Within The First Week. Simply The Best Nitric Oxide Supplements You've Ever Tried!","GOOD FOR YOUR HEART: L-Arginine Boosts Nitric Oxide Production For Fast Muscle Building, A Healthy Heart, and Fast Muscle Growth. Nitric Oxide Increases Workout Performance, Giving You The Best Muscle Pump You've Ever Had, As Well As Increasing Blood Flow From The Heart To Every Area Of The Body.","#1 TOP RATED FORMULA: Sheer Strength NO2 Is The ONLY Popular Nitric Oxide Booster That Contains L Citrulline, One Of Nature's Most Powerful NO2 Boosters. As A Result, You Get The Best Workout You've Ever Had From The Biggest Nitric Oxide Booster You've Ever Imagined!","BOOST MALE PERFORMANCE: Because Sheer Strength NO2 Increases Blood Flow To The Muscles, It Gives You A Blood Flow Post To \"Other\" Areas Of The Body As Well. The Ladies Will Notice - Trust Us, You'll Feel It.","30-DAY 100% MONEY BACK GUARANTEE - Return Even The Empty Bottles! We're So Confident That You'll Love Sheer Strength NO2 That We'll Refund Every Penny If You Don't Like It! What Do You Have To Lose? You'll Either Add Muscle And Increase Performance, Or You'll Lose Nothing."],"Label":"Sheer Strengths Labs","ListPrice":{"Amount":"4999","CurrencyCode":"USD","FormattedPrice":"$49.99"},"Manufacturer":"Sheer Strengths Labs","PackageDimensions":{"Height":"280","Length":"560","Weight":"40","Width":"290"},"PackageQuantity":"1","ProductGroup":"Health and Beauty","ProductTypeName":"HEALTH_PERSONAL_CARE","Publisher":"Sheer Strengths Labs","Studio":"Sheer Strengths Labs","Title":"SHEER NO2: #1 Best Nitric Oxide Supplement \u25cf The Top-Rated Nitric Oxide Booster from Sheer Strength Labs \u25cf Build Muscle and Strength Or It's Free: 30-Day 'Thrilled Customer' 100% Guarantee!","UPC":"820103175005","UPCList":{"UPCListElement":"820103175005"}},"OfferSummary":{"LowestNewPrice":{"Amount":"2897","CurrencyCode":"USD","FormattedPrice":"$28.97"},"TotalNew":"3","TotalUsed":"0","TotalCollectible":"0","TotalRefurbished":"0"},"Offers":{"TotalOffers":"1","TotalOfferPages":"1","MoreOffersUrl":"http:\/\/www.amazon.com\/gp\/offer-listing\/B00CCHBA8U%3FSubscriptionId%3DAKIAIBYRBZ…nkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB00CCHBA8U","Offer":{"OfferAttributes":{"Condition":"New"},"OfferListing":{"OfferListingId":"5VwspO4u6OeAyJa4bmxDQYHPX1ciZrmTun9TFOkY2Vc7Ie7tM26%2BnlZbnjCcrARqH9DbNeH4oH6SZfOJjiXztuZQe4T45r0cgXoObB5CxAI5QHA8lv6qLZfdhDzBNW2CTyLM4BRH2kktc62jGUSt7Q%3D%3D","Price":{"Amount":"2897","CurrencyCode":"USD","FormattedPrice":"$28.97"},"AmountSaved":{"Amount":"2102","CurrencyCode":"USD","FormattedPrice":"$21.02"},"PercentageSaved":"42","Availability":"Usually ships in 24 hours","AvailabilityAttributes":{"AvailabilityType":"now","MinimumHours":"0","MaximumHours":"0"},"IsEligibleForSuperSaverShipping":"1","IsEligibleForPrime":"1"}}},"CustomerReviews":{"IFrameURL":"http:\/\/www.amazon.com\/reviews\/iframe?akid=AKIAIBYRBZRR7WVI3CMQ&alinkCode=xm2&asi…-03T06%3A00%3A22Z&v=2&sig=3cE3oKNNqXv8nRZIi4UvzMrDgQhXo%2BhfqdlN8rHAtNo%3D","HasReviews":"true"},"EditorialReviews":{"EditorialReview":{"Source":"Product Description","Content":"<p><b>Are Nitric Oxide Supplements The Secret To Muscle Growth and Performance?<\/b><\/p> \n<p>\"I've tried about all there is to try to gain a competitive edge as far as supplements go. 'Sheer Strength' is one of the best I have taken without the nasty side effects or jitters.\" \u00ad Nithanial Decker<\/p> \n<p>\"Within a month, everyone could see a difference in my physique. The difference is amazing!\" - From Recent Reviews<\/p> \n<p>As the #1-rated nitric oxide supplement used by athletes, bodybuilders, and healthy people everywhere, Sheer Strength NO2 <b>boosts muscle growth<\/b> while being good for your heart and immune system. Sheer Strength NO2 helps your body produce more nitric oxide, giving you <b>more energy, more explosiveness, a healthy heart, and boosted strength<\/b>. <\/p> \n<p>This nitric oxide booster contains ingredients that are involved in \"wound healing, helping the kidneys remove waste products from the body, [and] maintaining immune and hormone function.\" They have also been featured on TV as a powerful and natural way to increase reps and strength in the gym.<\/p> \n<p>At Sheer Strength Labs, we give you the maximum active ingredients and less of the junk that your body doesn't need. <b>Our challenge: Take one bottle for thirty days. If you don't gain muscle, feel stronger, and have more energy, we'll buy it back from you!<\/b> But keep your new muscles as a THANK YOU for trying it out.<\/p> \n<p><b>Money Back Guarantee:<\/b> if you aren't thrilled with the results that you get from Sheer Strength NO2, simply return the product (even the empty bottles) to Amazon for a full money back guarantee.<\/p>","IsLinkSuppressed":"0"}},"SimilarProducts":{"SimilarProduct":[{"ASIN":"B00KGOCK5S","Title":"SHEER STRENGTH BCAA Capsules - Burn Fat and Build Muscle Now With The Best Branch Chain Amino Acid Supplement - Full 30 Day Supply"},{"ASIN":"B00H4IBD0M","Title":"SHEER TESTOSTERONE - #1 Best Testosterone Booster With Fenugreek \u25cf 100% Natural Testosterone Booster for Men \u25cf Science-Backed Formula Naturally Builds Muscle, Burns Fat, and Boosts Male Performance"},{"ASIN":"B00UVXQ9Q0","Title":"SHEER ALPHA: The Best Testosterone Booster For Men \u25cf FINALLY Get The Body You Want With The #1 Top-Rated Muscle Builder Supplement on Amazon - 100% Natural Science-Based Formula Delivers REAL Results"},{"ASIN":"B00QETHBP8","Title":"Sheer Strength Labs Creatine Monohydrate - 500g - 100 Servings"},{"ASIN":"B00N48DV92","Title":"SHEER THERMO: The #1 Best Fat Burning Thermogenic Supplement \u25cf Proven Science-Based Formula With Yohimbe + Yohimbine +More \u25cf Burn Fat and Lose Weight Fast With The Most Effective Fat Burner Available"}]},"BrowseNodes":{"BrowseNode":[{"BrowseNodeId":"6973678011","Name":"Supplements","Ancestors":{"BrowseNode":{"BrowseNodeId":"6973669011","Name":"Endurance & Energy","Ancestors":{"BrowseNode":{"BrowseNodeId":"6973663011","Name":"Sports Nutrition","Ancestors":{"BrowseNode":{"BrowseNodeId":"3760931","Name":"Products","IsCategoryRoot":"1","Ancestors":{"BrowseNode":{"BrowseNodeId":"3760901","Name":"Health & Personal Care"}}}}}}}}},{"BrowseNodeId":"6973698011","Name":"Nitric Oxide Boosters","Ancestors":{"BrowseNode":{"BrowseNodeId":"6973697011","Name":"Pre-Workout","Ancestors":{"BrowseNode":{"BrowseNodeId":"6973663011","Name":"Sports Nutrition","Ancestors":{"BrowseNode":{"BrowseNodeId":"3760931","Name":"Products","IsCategoryRoot":"1","Ancestors":{"BrowseNode":{"BrowseNodeId":"3760901","Name":"Health & Personal Care"}}}}}}}}}]}}}},{"OperationRequest":{"HTTPHeaders":{"0":{"@attributes":{"Name":"UserAgent","Value":"ApaiIO [2.0.0-DEV]"}}},"RequestId":"b9f1bfbf-e54d-413b-b245-64ba721040eb","Arguments":{"Argument":[{"@attributes":{"Name":"AWSAccessKeyId","Value":"AKIAIBYRBZRR7WVI3CMQ"}},{"@attributes":{"Name":"AssociateTag","Value":"heyadme-20"}},{"@attributes":{"Name":"ItemId"}},{"@attributes":{"Name":"Operation","Value":"ItemLookup"}},{"@attributes":{"Name":"ResponseGroup","Value":"Large"}},{"@attributes":{"Name":"Service","Value":"AWSECommerceService"}},{"@attributes":{"Name":"Timestamp","Value":"2015-10-02T18:30:10Z"}},{"@attributes":{"Name":"Version","Value":"2011-08-01"}},{"@attributes":{"Name":"Signature","Value":"kdOwdicnfDgj6YX6YGHfVdribMtPrXDOBYz6x8fOnM8="}}]},"RequestProcessingTime":"0.0019940000000000"},"Items":{"Request":{"IsValid":"False","ItemLookupRequest":{"IdType":"ASIN","ResponseGroup":"Large","VariationPage":"All"},"Errors":{"Error":{"Code":"AWS.MissingParameters","Message":"Your request is missing required parameters. Required parameters include ItemId."}}}}}]
抱歉这么长的json。
答案 0 :(得分:0)
请将php return设为json,如下所示:
$json = '{}';
header('Content-Type: application/json');
echo json_encode($json);
答案 1 :(得分:0)
JSON.parse()方法将字符串解析为JSON,可选地转换解析产生的值。
语法 JSON.parse(text [,reviver])
而
JSON.stringify()方法将JavaScript值转换为JSON字符串,如果指定了replacer函数,则可以选择替换值,或者如果指定了replacer数组,则可以选择仅包含指定的属性。
以下是我在jsfiddle
上对你的JSON所做的