php - JSON 中的奇怪字符(在 cURL 身份验证后获得)

标签 php arrays curl json

这是我用来从 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/

相关文章:

php - 使用 PHP 拉入 RSS 提要时提取图像数据

php - 根据相同或不同的值检查并更新行

php - 如何将 MySQL 数据库自动复制到同一服务器上的另一个 MySQL 数据库?

python - 替换索引数组下方的 numpy 二维数组元素

php - cURL 后存储的数据没有空格

php - 无法使用 PHP INSERT INTO 数据库,没有抛出错误

c - 为什么我的代码不能正确运行该函数

Android - 从 db 创建一个可绘制对象数组

c++ - 如何将 CURLOPT_DNS_CACHE_TIMEOUT 与共享 DNS 缓存一起使用

javascript - PHP : Curl a page, 应用javascript并保存结果