如何修复JSON响应中Datetime来的空间

时间:2019-07-08 11:31:10

标签: php json

我想删除从datetime获得的空间。由于此JSON格式无效。 以下是我的JSON响应:

{
"txId": "226334",
"createdAt":"2019-06-20
18: 33: 51","details":"Transfered
out","account_name_2":"","currency":"myr","amount":"-44.00","balance":"44,
272.80"}

下面是我的代码

$data['transactions'] = [];
        foreach ($transactions as $tx) {
            $data['transactions'][] = array(
                'txId' => $tx['id'],
                'createdAt' => trim($tx['created_at']),
                'details' => str_replace(" "," ",$this->lang->line($tx['description'])),
                'account_name_2' => isset($merchants[$tx['account_name_2']]) ? $merchants[$tx['account_name_2']] : $tx['account_name_2'],
                'currency' => $currency,
                'amount' => $tx['amount'] > 0 ? '+' . number_format($tx['amount'] * $forex['buy_in'], 2) : number_format($tx['amount'] * $forex['buy_in'], 2),
                'balance' => number_format($total * $forex['buy_in'], 2)
            );
            $total -= number_format($tx['amount'] * $forex['buy_in'], 2);
        }

        $this->respSuccess($data);

1 个答案:

答案 0 :(得分:0)

尝试str_replace

str_replace("\n","",$json);

如果需要str_replace("\n"," ",$json);

,可以用空格代替

Check Here