Skip to main content
 首页 » 编程设计

php之JSON格式化额外字符

2024年10月24日24arxive

我正在尝试通过 API 使用 Python 发送一些 JSON。它有效,但它添加了一堆时髦的字符,我不知道为什么或它们的意思。

我正在做的是转换这个“body”变量:

+++[git checkout hashhashhash]+++ 
 
+++[git diff --name-status master]+++ 
 
M       file.php 
 
1 files changed. 

为此:

body = {"body":"{{noformat}}{0}{{noformat}}".format(body)} 

完成后,'body' 变成这样:

{'body': '{noformat}\n+++[git checkout hashashashashash]+++\n+++[git diff --name-status master]+++\n\x1b[?1h\x1b=M       file.php\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>\n1 files changed.\n{noformat}'} 

这完全没问题,除了这是通过 API 发送后发布的内容:

+++[git checkout hashashashashashash]+++ 
 
+++[git diff --name-status master]+++ 
 
[?1h=M       file.php[m 
 
[K[?1l> 
1 files changed. 

我还没有弄清楚是怎么回事。 [?1h=M 和 [K[?1l> 有何关系,如何让它们消失?

请您参考如下方法:

我想您会发现这些是 git 发送的终端初始化序列 - function-key-mode on 和 function-key-mode off 是准确的。

在生成原始 Git 输出时尝试使用 --no-pager 选项。