douling0053 2015-12-29 23:45
浏览 374
已采纳

使用带有json_decode的php中的Base64解码json字符串

I'm trying to decode output json data using json_decode & Base64 decode, no issue for output json_decode but one string that have base64 encode I also no issue to decode it using base64_decode,. but I'm try to decode both json data using json_decode & base64_decode that i face some problems, My question is now how to decode the JSON string on same time one string use base64 decode... here an example of my json data

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' as output working ..but with limit array [0] << one output only if i replace $output[0] with $output[1] i got output of array 1 like that ,,i need to be dynamic [0] or [1] or [2] ..etc base on output.. ,,and print the other strings with 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);

?>

thanks

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 这段有什么bug 为什么总报错
      • ¥15 关于#php#根据url判断选择加载模板应该如何解决?会的速来捡钱!
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云
      • ¥50 unity使用easyar录屏更换视频保存路径
      • ¥15 CECGameSession::OutputLinkSevError(iRetCode=4) LINK超时
      • ¥20 出错 textread (第 124 行) [varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
      • ¥15 tensor flow目标检测环境配置问题
      • ¥15 数据库float型转换精度问题
      • ¥15 运行您代码时出现报错,如何解决?(标签-回归|关键词-无法识别)
      • ¥50 android service弹出dialog,showdialog就出错,如何解决?