这是我用来从 Feedbin API 中获取 JSON 文件的函数.
<?php
error_reporting(E_ALL);
// JSON URL which should be requested
$json_url = 'https://api.feedbin.me/v2/entries.json';
$username = 'my_username'; // authentication
$password = ' my_password'; // authentication
// Initializing curl
$ch = curl_init( $json_url );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $username . ":" . $password // authentication
);
// Setting curl options
curl_setopt_array( $ch, $options );
// Getting results
$result = curl_exec($ch); // Getting JSON result string
print_r ($result);
?>
问题是我得到的 JSON 有点……奇怪。 它有很多字符,例如 \u003E\u003C/a\u003E\u003C/p\u003E\n\u003Cp\u003E ... 您可以看到 JSON here .
最佳答案
当您在 PHP 中对包含这些编码的字符串调用 json_decode
时,它们将被正确解码。 http://json.org/将 \ufour-hex-digits
列为有效字符。没有问题。
$ echo json_decode('"\u003E\u003C/a\u003E\u003C/p\u003E\n\u003Cp\u003E"');
></a></p>
<p>
关于php - JSON 中的奇怪字符(在 cURL 身份验证后获得),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16968843/