嗨我是json和php的新手,我尝试在php中循环解析json数据,但它返回空。
请帮忙。这是我的代码:
这是我的表数据
|id|data|
_________
|11|[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]|
_________
|12|[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"New Company"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Michael"}]|
_________
|13|[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Blitzc inc"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Yudha"}]|
_________
答案 0 :(得分:0)
您需要将第二个参数设置为true
,以告诉它将结果作为关联数组返回。
$array = json_decode($array, true);
这在PHP手册中非常清楚地记录了here。
然后,您可以像这样访问value
:
$array['value']
答案 1 :(得分:0)
你的问题是table
是保留的MySQL字。试试这个问题:
$sql = "SELECT id, data FROM `table`";
然后对我来说,你所有的代码都运行良好