这是代码:
//require necessary files
require_once('../app/Mage.php');
$categoryID = $_POST['categoryID'];
//necessary initialization
Mage::app();
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
try{
$json = array('status' => true);
$json['data'] = array();
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($categoryID); // 3rd Category
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$count[] = array('attribute_name' => $option->getLabel(),'attribute_value' => $option->getValue());
}
if($count!=null){
$json['data'][] = array('name'=>ucfirst($attribute->getAttributeCode()),'count'=>$count);
}
unset($count);
}
}
catch (Exception $e) {
$json = array('status' => false, 'message' => $e->getMessage());
}
echo json_encode($json);
这是输出:
答案 0 :(得分:1)
更改
x = sc.next();
到
x = sc.nextLine();
以消耗行尾字符。
除此之外,
Line = Line + " " + NewLine;
将新行连接到所有前面的行。我不确定你想要什么(基于你System.out.println ("Your new Line is: " + Line);
的打印)。
最后一件事:
while (!"N".equals(x) && "Y".equals(x));
是多余的。如果x
等于"Y"
,则它不等于"N"
,所以它足以写出:
while ("Y".equals(x));