我有一个json字符串,我想解析为小数组的对象,我正在使用解码器,但它不会有帮助,为什么这很开心?
我已将变量定义为$ cleanforcharacters
$cleanforcharacters = preg_replace('/["{mtwrdayfsasusseto}"]_/', '', $found['newdiscounthours']);
这是我的输出
discount_org: "{"day":"8:00","time":"12:00","discount":"10","day":"8:00","time":"12:00","discount":"10"}"
这是期望的输出(对象数组)
discount_org: [
{
day: 0,
time: 8,
discount: 10
},
{
day: 0,
time: 14,
discount: 10
},
这是我试过的方式
$ arrayOfEmails = json_decode($ cleanforcharacters);
这就是我现在得到的
discount_org: {
day: "20",
time: "12:00",
discount: "20"
}
剩下的就不出来了
答案 0 :(得分:0)
这是因为你已经声明它作为一个对象并且键覆盖了值而不是被设置为新值: -
您已经: -
discount_org: "{"day":"8:00","time":"12:00","discount":"10","day":"8:00","time":"12:00","discount":"10"}"
应该是: -
discount_org: "[{"day":"8:00","time":"12:00","discount":"10"},{"day":"8:00","time":"12:00","discount":"10"}]"
然后使用: -
$arrayOfEmails = json_decode($cleanforcharacters,true);
这会给你正确的结果。