PHP的JSON解码包含破折号的变量 [英] php json decode with variables that contains dashes

查看:118
本文介绍了PHP的JSON解码包含破折号的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{"general":{
 "round-corner":"0",
 "border-stroke":"2",
 "background-color":"#ffffff"
 }
}

我有这个json字符串,我知道php变量名称不支持破折号.那么在这种情况下该怎么办?

I have this json string, I know that php variable names doesn't support dashes. So what to do in this case ?

推荐答案

您可以使用像这样的数组格式.连字符的键将起作用.

You can use an array format like this. Hyphened keys will work.

<?php

$json = '{"general":{
 "round-corner":"0",
 "border-stroke":"2",
 "background-color":"#ffffff"
 }
}';

$array = json_decode($json, true);

echo $array['general']['border-stroke']; // prints 2

?>

这是演示

这篇关于PHP的JSON解码包含破折号的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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