无法解码json字符串
我有一个json字符串,我想解析成一个小的对象数组,我正在使用解码器,但它没有帮助,为什么会发生这种情况 我已经将变量定义为$cleanforcharacters无法解码json字符串,json,Json,我有一个json字符串,我想解析成一个小的对象数组,我正在使用解码器,但它没有帮助,为什么会发生这种情况 我已经将变量定义为$cleanforcharacters $cleanforcharacters = preg_replace('/["{mtwrdayfsasusseto}"]_/', '', $found['newdiscounthours']); 这是我的输出 discount_org: "{"day":"8:00","time":"12:00","discount":"10","d
$cleanforcharacters = preg_replace('/["{mtwrdayfsasusseto}"]_/', '', $found['newdiscounthours']);
这是我的输出
discount_org: "{"day":"8:00","time":"12:00","discount":"10","day":"8:00","time":"12:00","discount":"10"}"
这是所需的输出(对象数组)
我就是这样尝试的
$arrayOfEmails=json_decode($cleanforcharacters)
这就是我现在得到的
discount_org: {
day: "20",
time: "12:00",
discount: "20"
}
其余的也不会出现这是因为您已声明,作为一个对象,键将覆盖这些值,而不是设置为新值:- 你给出了:-
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);
这将给出正确的结果。这不是因为它是字符串而不是对象吗?如果是这样,我认为解码器不能处理字符串
$arrayOfEmails = json_decode($cleanforcharacters,true);