如何在PHP中循环遍历此json解码数据? [英] How to loop through this json decoded data in PHP?

查看:489
本文介绍了如何在PHP中循环遍历此json解码数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要解码的JSON产品列表:

I've have this list of products in JSON that needs to be decoded:

"[{"productId":"epIJp9","name":"Product A","amount":"5","identifier":"242"},{"productId":"a93fHL","name":"Product B","amount":"2","identifier":"985"}]"

使用json_decode()在PHP中对其进行解码后,我不知道输出是哪种结构.我以为它将是一个数组,但是在我要求count()之后,它说它是"0".如何遍历这些数据,以便获得列表中每种产品的属性.

After I decode it in PHP with json_decode(), I have no idea what kind of structure the output is. I assumed that it would be an array, but after I ask for count() it says its "0". How can I loop through this data so that I get the attributes of each product on the list.

谢谢!

推荐答案

要将json转换为数组,请使用

To convert json to an array use

 json_decode($json, true);

这篇关于如何在PHP中循环遍历此json解码数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆