如何解决由于通知错误,无法访问 api 数据
抱歉,无法显示准确的 json 文件内容和 API URL 链接
<b>Notice</b>: Undefined index: api_token in <b>/home/websitename/public_html/catalog/controller/startup/session.PHP</b> on line <b>8</b>{
"products": [
{
"product_id": "480","thumb": "https://exmaple.com/image/cache/catalog/401/a32-1000x1000-270x270.png","name": "Product Name","description": "discription","special": false,"tax": false,"minimum": "1","rating": 0,"href": "http://example.com/index.PHP?route=product/product&product_id=480"
},]
}
这是我未来的功能
Future<ProductModel> getProducts() async {
final String apiUrl = "https://www.example.com";
final http.Response response = await http.get(apiUrl);
var productModel;
try {
if (response.statusCode == 200) {
var jsonString = response.body;
var jsonMap = json.decode(jsonString);
productModel = ProductModel.fromJson(jsonMap);
}
} catch (Exception) {
print(Exception);
}
return productModel;
}
<?PHP
class ControllerApiProduct extends Controller
{
public function index()
{
$this->load->language('api/cart');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$json = array();
$json['products'] = array();
$filter_data = array();
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'],$this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'),$this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png',$this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'],$result['tax_class_id'],$this->config->get('config_tax')),$this->session->data['currency']);
} else {
$price = false;
}
if ((float) $result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'],$this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float) $result['special'] ? $result['special'] : $result['price'],$this->session->data['currency']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int) $result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],'thumb' => $image,'name' => $result['name'],'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'],ENT_QUOTES,'UTF-8'))),$this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..','price' => $price,'special' => $special,'tax' => $tax,'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,'rating' => $result['rating'],'href' => $this->url->link('product/product','product_id=' . $result['product_id']),);
}
$json['products'] = $data['products'];
$this->response->addHeader('Content-Type: application/json');
$this->response->setoutput(json_encode($json));
}
}
这是我未来构建器的代码
FutureBuilder<ProductModel>(
future: _productModel,builder: (context,snapshot) {
if (snapshot.hasData) {
print(snapshot.data.products.length);
return GridView.builder(
itemCount: snapshot.data.products.length,gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),itemBuilder: (context,index) {
return SingleProduct(
prodName: snapshot.data.products[index].name,prodPicture: snapshot.data.products[index].thumb,// prodoldPrice: productList[index]['oldPrice'],prodPrice: snapshot.data.products[index].price,prodDescription: snapshot.data.products[index].description,prodId: snapshot.data.products[index].productId,);
},);
} else {
// return CircularProgressIndicator();
return CircularProgressIndicator();
}
});
我的代码正在运行,但由于此通知而无法获取 API 数据<b>Notice</b>: Undefined index: api_token in <b>/home/example/public_html/catalog/controller/startup/session.PHP</b> on line <b>8</b>
是否有解决此问题的解决方法。
确切的错误如下:
I/Flutter (12559): FormatException: Unexpected character (at character 1)
I/Flutter (12559): <b>Notice</b>: Undefined index: api_token in <b>/home/example/public_htm...
I/Flutter (12559): ^
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。