?php
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都做网站、新昌网络推广、微信小程序开发、新昌网络营销、新昌企业策划、新昌品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供新昌建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
$json =
'{
"success": true,
"total": 1592,
"yi18": [
{
"id": 58382,
"img": "img/cook/000058382.jpg",
"keywords": "",
"description": "",
"content": "font color=\"red\"南瓜/font的好处: 防癌:font color=\"red\"南瓜/font能消除亚硝酸胺的突变作用,制止癌细胞出现。 杜虫:font color=\"red\"南瓜/font籽具有很好的杀灭血吸虫幼虫作用,对于蛲虫病、蛲虫病等患者疗效显著(方法是空腹细嚼后吞服font color=\"red\"南瓜/font籽)。 治高血压:多吃",
"type": "cook",
"name": "美味font color=\"red\"南瓜/font汁"
},
{
"id": 58381,
"img": "img/cook/000058381.jpg",
"keywords": "",
"description": "",
"content": "font color=\"red\"瓜/font的好处: 防癌",
"type": "cook",
"name": "美味font color=\"red\"瓜/font汁"
}
]
}';
$arr = json_decode($json, True);
for($i=0;$icount($arr['yi18']);$i++)
{
$name = $arr['yi18'][$i]['name'];
//if($name == '美味font color=\"red\"瓜/font汁')
//{
// echo '是美味南瓜汁';
//}
}没时间了,先写点代码供参考。
你可以把JSON字符串转成数组,数组转过来不是数组那肯定不是JSON数据。
$str = '{"queryString":"select id , name from user LIMIT 0, 30 ","data":[{"0":"1","id":"1","1":"aa","name":"aa"},{"0":"2","id":"2","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"3","id":"3","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"4","id":"4","1":"44","name":"44"},{"0":"5","id":"5","1":"","name":""},{"0":"6","id":"6","1":"","name":""},{"0":"7","id":"7","1":"","name":""},{"0":"8","id":"8","1":"","name":""},{"0":"9","id":"9","1":"","name":""},{"0":"10","id":"10","1":"jiejie","name":"jiejie"},{"0":"11","id":"11","1":"jiejie","name":"jiejie"}]}';
foreach (json_decode($str) as $v)
{
if(is_array($v))
{
foreach($v as $value)
{
echo "当前的name 为: {$value-name} id : {$value-id}";
}
}
}
中文不管 你取得是对应的name值
if(!json_decode($json))
{
//不是
}
else
{
//是
}
function is_not_json($str){
return is_null(json_decode($str));
}
function is_json($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
JSON很好识别的,如果你不确定是否是JSON格式那么你用json_decode对那个字符串进行解码判断,PHP官方对这个函数的返回值的说明是:返回值JSON编码的。值true,false和空(不区分大小写)返回TRUE,FALSE和NULL。如果的JSON不能被解码或者如果编码的数据是深度超过递归限制,则返回NULL。