首先要记住json_encode返回的是字符串, 而json_decode返回的是对象.
判断数据不是JSON格式:
function is_not_json($str){ return is_null(json_decode($str));}
判断数据是合法的json数据: (PHP版本大于5.3)
function is_json($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE);}
注意: json编解码所操作字符串必须是UTF8的.
by iefreer
参考:
http://www.php.net/manual/en/ref.json.php
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow