我有一个像这样的json对象:
{"Techne":{"@Version":"2.2","Author":"ZeuX","Name":"","PreviewImage":"","ProjectName":"","ProjectType":"","Description":"","DateCreated":"","Models":[{"Model":{"GlScale":"1,1,1","Name":"","TextureSize":"1,1","@texture":"texture.png","BaseClass":"ModelBase","Geometry":{"Folder":[],"Shape":[],"Piece":[],"Null":[]}}}]}}
如何使用PHP检查数组Shape:[]是否为空我只知道如何使用JavaScript但这个问题需要使用PHP我该怎么办?
答案 0 :(得分:0)
您可以使用json_decode()然后访问其成员。
$json = json_decode('{"Techne":{"@Version":"2.2","Author":"ZeuX","Name":"","PreviewImage":"","ProjectName":"","ProjectType":"","Description":"","DateCreated":"","Models":[{"Model":{"GlScale":"1,1,1","Name":"","TextureSize":"1,1","@texture":"texture.png","BaseClass":"ModelBase","Geometry":{"Folder":[],"Shape":[],"Piece":[],"Null":[]}}}]}}');
if(empty($json->Techne->Models[0]->Model->Geometry->Shape))
echo "Shape is empty";
在这种情况下, json_decode()
会给你一个对象,因为这就是这个JSON字符串的格式。您可以通过搜索JSON和PHP来了解更多信息,有很多教程可以帮助您更好地理解。
我希望它对你有所帮助。