我知道 PHP 已经提供了 JSON_PRETTY_PRINT 来格式化 json 数据。如果我想要不同的格式怎么办?
$message = array(
"Open all day" => "Sundays,Saturdays,12-12-2013, 14-10-2013",
"Availabilty" => array(
"12/12/2013" => array(
30,
60,
30,
0
),
"13/12/2013" => array(
30,
0,
30,
60,
),
),
);
$json = json_encode($message,JSON_PRETTY_PRINT);
结果,
{
"Open all day": "Sundays,Saturdays,12-12-2013, 14-10-2013",
"Availabilty": {
"12\/12\/2013": [
30,
60,
30,
0
],
"13\/12\/2013": [
30,
0,
30,
60
]
}
}
但是我更喜欢,
{"Open all day":"
Sundays,
Saturdays,
Fridays,
12/12/2013,
14/10/2013,
04/12/2013
",
"Availability":"
"12/12/2013":[30,60,30,0],
"13/12/2013":[30,60,30,0]
"}
那可能吗?也许是一个正则表达式?另外,我不想要那些反斜杠 - 它们可以被删除吗?