在 php 和 json_decode 中使用 Base64 解码 json 字符串
Decode json string using Base64 in php with json_decode
我正在尝试使用 json_decode 和 Base64 解码解码输出 json 数据,输出没有问题 json_decode 但是一个具有 base64 编码的字符串我也没有解码问题它使用 base64_decode,。但我尝试使用 json_decode 和 base64_decode 解码两个 json 数据,我遇到了一些问题,我现在的问题是如何同时解码 JSON 字符串字符串使用 base64 解码...这里是我的 json 数据
的示例
Array
(
[0] => Array
(
[ad_id] => 257
[stat] => 1
[text] => 2YTZhNio2YrYuSDYtNmB2LEg2YPYp9io2KrZitmB2YrYpyDZhdmI2K/ZitmEINmi2aDZoNmp
[img_count] => 4
[img_file_name] => 8246ee83.jpg
)
[1] => Array
(
[ad_id] => 258
[stat] => 1
[text] => 2YTZhNio2YrYuSDYtNmB2LEg2KfZhCDYqtmKINiy2K8g2YXZiNiv2YrZhCDZotmg2aDZpQ==
[img_count] => 5
[img_file_name] => 1563457.jpg
)
string 'text' 作为输出工作..但是限制数组 [0] << 只有当我用 $output[1] 替换 $output[0] 时才输出一个我得到数组 1 的输出,我需要根据输出是动态的 [0] 或 [1] 或 [2] ..etc .. ,并用 json_decode.
打印其他字符串
<?
$ch = curl_init("http://www.example.com/s=0&c=20");
curl_setopt( $ch, CURLOPT_USERAGENT, 'Dalvik/2.1.0 (Linux; U; Android 5.0; SM-N9005 Build/LRX21V)' );
curl_setopt($ch,CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip'));
$result = curl_exec($ch);
$json = json_decode( $result, TRUE);
$output[0]['text']=base64_decode($json[0]['text']);
header('Content-Type: text/plain; charset=utf-8');
#print_r ($json);
print_r ($output);
?>
谢谢
我明白了,这样做:
$json = json_decode($result, true);
foreach($json as $k => $v){ // this will loop through all the possible indexes
$output[$k]['text'] = base64_decode($v['text']);
}
header('Content-Type: text/plain; charset=utf-8');
print_r($output); // here's your new PHP array with all the ['text'] values!
我正在尝试使用 json_decode 和 Base64 解码解码输出 json 数据,输出没有问题 json_decode 但是一个具有 base64 编码的字符串我也没有解码问题它使用 base64_decode,。但我尝试使用 json_decode 和 base64_decode 解码两个 json 数据,我遇到了一些问题,我现在的问题是如何同时解码 JSON 字符串字符串使用 base64 解码...这里是我的 json 数据
的示例Array
(
[0] => Array
(
[ad_id] => 257
[stat] => 1
[text] => 2YTZhNio2YrYuSDYtNmB2LEg2YPYp9io2KrZitmB2YrYpyDZhdmI2K/ZitmEINmi2aDZoNmp
[img_count] => 4
[img_file_name] => 8246ee83.jpg
)
[1] => Array
(
[ad_id] => 258
[stat] => 1
[text] => 2YTZhNio2YrYuSDYtNmB2LEg2KfZhCDYqtmKINiy2K8g2YXZiNiv2YrZhCDZotmg2aDZpQ==
[img_count] => 5
[img_file_name] => 1563457.jpg
)
string 'text' 作为输出工作..但是限制数组 [0] << 只有当我用 $output[1] 替换 $output[0] 时才输出一个我得到数组 1 的输出,我需要根据输出是动态的 [0] 或 [1] 或 [2] ..etc .. ,并用 json_decode.
打印其他字符串<?
$ch = curl_init("http://www.example.com/s=0&c=20");
curl_setopt( $ch, CURLOPT_USERAGENT, 'Dalvik/2.1.0 (Linux; U; Android 5.0; SM-N9005 Build/LRX21V)' );
curl_setopt($ch,CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip'));
$result = curl_exec($ch);
$json = json_decode( $result, TRUE);
$output[0]['text']=base64_decode($json[0]['text']);
header('Content-Type: text/plain; charset=utf-8');
#print_r ($json);
print_r ($output);
?>
谢谢
我明白了,这样做:
$json = json_decode($result, true);
foreach($json as $k => $v){ // this will loop through all the possible indexes
$output[$k]['text'] = base64_decode($v['text']);
}
header('Content-Type: text/plain; charset=utf-8');
print_r($output); // here's your new PHP array with all the ['text'] values!