1
我想验证输入是否有效json。但是,它返回“123”作为输入的成功。这似乎不是有效的,或者至少在我所需要的方面是无效的。表单请求验证JSON
你知道一种改进json输入验证的方法吗?
public function rules()
{
switch($this->method()) {
case "GET":
return [];
case "DELETE":
return [];
default:
return [
'name' => 'required',
'templatestring' => 'required|JSON'
];
}
}
就有关PHP而言,'123' *是有效的JSON。 'json_decode('123')'或者试试http://jsonlint.com/。 – ceejayoz