Home  >  Article  >  Backend Development  >  The bottom layer returns such a json string. How to replace n and t with the corresponding carriage return and tab symbols in the front end or PHP part?

The bottom layer returns such a json string. How to replace n and t with the corresponding carriage return and tab symbols in the front end or PHP part?

WBOY
WBOYOriginal
2016-12-01 01:27:571429browse

<code>{"msg":"{\n \"iaback\" : {\n \"code\" : -3522,\n \"msg\" : \"\"\n },\n \"iawork\" : {\n \"code\" : 0,\n \"msg\" : \"---------------LibRxTx Info:--------------\\nCurrent peer:\\t4\\nWork Thread 0 235\\nWork Thread 1 255\\nWork Thread 2 247\\nWork Thread 3 244\\nEpLoop\\t\\t2513\\nEpRead\\t\\t1876\\nEpMoreRead\\t0\\nEpWrite\\t\\t895\\nSndLoop\\t\\t2183\\nPeerSnd\\t\\t1805\\nSndSw\\t\\t0\\nBufSnd\\t\\t908\\nAccept\\t\\t1778\\nPeerRcv\\t\\t1085\\nBufRcv\\t\\t1974\\nAddJob\\t\\t988\\nGetJob\\t\\t986\\nGetMore\\t\\t985\\nPktSnd\\t\\t888\\nPktRcv\\t\\t889\\nSndWait\\t\\t0\\nSndWaitAck\\t0\\n-------> Epoll 0\\nIdx ID RID State pktSnd ackRcv pktRcv pktExe ackSnd bw(Bps) Zip Retry\\tName\\n0 1 0 Lsn 0 0 0 0 0 -1 100 0\/-1\\t 127.0.0.1:26826 <--> :\\n1 2 0 Try 0 0 0 0 0 -1 100 96\/-1\\t :44115 <--> 192.168.17.9:26828\\n2 891 0 OK 0 0 1 0 0 -1 100 0\/-1\\tIPC 127.0.0.1:26826 <--> 127.0.0.1:57872\\n\"\n }\n}\n","result":0} 
</code>

我想在前端显示格式化的易读的json串

回复内容:

<code>{"msg":"{\n \"iaback\" : {\n \"code\" : -3522,\n \"msg\" : \"\"\n },\n \"iawork\" : {\n \"code\" : 0,\n \"msg\" : \"---------------LibRxTx Info:--------------\\nCurrent peer:\\t4\\nWork Thread 0 235\\nWork Thread 1 255\\nWork Thread 2 247\\nWork Thread 3 244\\nEpLoop\\t\\t2513\\nEpRead\\t\\t1876\\nEpMoreRead\\t0\\nEpWrite\\t\\t895\\nSndLoop\\t\\t2183\\nPeerSnd\\t\\t1805\\nSndSw\\t\\t0\\nBufSnd\\t\\t908\\nAccept\\t\\t1778\\nPeerRcv\\t\\t1085\\nBufRcv\\t\\t1974\\nAddJob\\t\\t988\\nGetJob\\t\\t986\\nGetMore\\t\\t985\\nPktSnd\\t\\t888\\nPktRcv\\t\\t889\\nSndWait\\t\\t0\\nSndWaitAck\\t0\\n-------> Epoll 0\\nIdx ID RID State pktSnd ackRcv pktRcv pktExe ackSnd bw(Bps) Zip Retry\\tName\\n0 1 0 Lsn 0 0 0 0 0 -1 100 0\/-1\\t 127.0.0.1:26826 <--> :\\n1 2 0 Try 0 0 0 0 0 -1 100 96\/-1\\t :44115 <--> 192.168.17.9:26828\\n2 891 0 OK 0 0 1 0 0 -1 100 0\/-1\\tIPC 127.0.0.1:26826 <--> 127.0.0.1:57872\\n\"\n }\n}\n","result":0} 
</code>

我想在前端显示格式化的易读的json串

你是想在浏览器上显示格式化的JSON?
var_export(json_decode($json_string));试试这个。可以格式化保存对象结构。
但你是浏览器上显示的话,估计上面这个不合适,他还打印了对象信息。
只显示JSON格式化字符,有两个办法,看你的PHP版本5.4以前的话要自己写处理函数,google一下一大堆。
5.4版本以后可以直接这样:
echo json_encode($arr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
打印结果就是完格格式化后的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn