复制public function yourMethod()
{
$data = [
[
"id" => 29,
"category_id" => 8,
"partner_id" => 2,
"name" => "香港沙田服务器 E3-1230 系列",
"sku_cpu" => "",
"sku_disk" => '{"adbdd20b1108181a":{"name":"240G SSD","price":"0"},"8be946835e534dbe":{"name":"1TB HDD","price":"0"},"95047284fe778fa2":{"name":"480G SSD","price":"32"}}',
"sku_ram" => '{"2125b9ea756d0cf1":{"name":"8G","price":"0"},"4344a677fd9efa90":{"name":"16G","price":"11"},"78a76c350ad42f61":{"name":"32G","price":"33"}}',
"sku_bandwidth" => '{"3b794a1c178240a9":{"name":"10M 优化","price":"0"},"94f264fcae36b180":{"name":"15M 全向","price":"0"},"08f960dff5a35ed6":{"name":"20M 国际","price":"0"}}',
"sku_ip" => '{"e215784748586b12":{"name":"3","price":"0"},"27ba07df1ce27b4e":{"name":"4","price":"4"},"e1af9ea515feede3":{"name":"5","price":"8"},"d895bce4e623f8c6":{"name":"6","price":"12"}}',
"sku_firewall" => '{"0e4b512eb1eafcf8":{"name":"0","price":"0"}}',
"sku_flow" => '[]',
"sku_gpu" => '[]',
"price_month" => '{"386a95adab8a4fe6":{"period":1,"cycle":"month","price":135,"setup":0,"discount":100},"07f9413c68442501":{"period":3,"cycle":"month","price":405,"setup":0,"discount":100}}',
"price_years" => null,
"is_sale" => 0,
"can_test" => 1,
"sku_raid" => '[]',
"sku_intranet" => '[]',
"sort" => 10,
"status" => 1,
"cpu_info" => null,
"cpu_model" => null
]
];
foreach ($data as &$item) {
foreach ($item as $key => $value) {
if (!empty($value) && $this->isJson($value)) {
$item[$key] = json_decode($value, true);
}
}
}
$this->assign('data', $data);
return $this->fetch();
}
private function isJson($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}