Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
PHP を追加した後header("Content-type: text/plain");、スペースが追加されます。私はきれいなJSONに使用します。
header("Content-type: text/plain");
私はこれを必要とする:
{ "コード":"200" } }
しかし、私はこれを取得します:
PHP ページをよく見てください。おそらく、(PHP タグの外側に) 気付いていない空白が含まれているだけです。}(そして、JSONに余分なものがあります...)
}
PHP 5.4 以降を使用している場合は、JSON_PRETTY_PRINTフラグを使用できます。
JSON_PRETTY_PRINT
ただし、メインページにない場合は、印刷の前に空白がある可能性があると思いますfunctions.php.
functions.php