doulie0178
2016-08-03 10:08
浏览 256

如何修复警告JSON_BIGINT_AS_STRING未实现?

Looking on my Apache error log file, I checked this warning:

PHP Warning:  json_decode(): option JSON_BIGINT_AS_STRING not implemented in /../codebird.php on line 2517

It's referred to a script that I use to auto-post on Twitter from my blog.

This is the guilty function:

  protected function _parseApiReply($reply)
  {
    $need_array = $this->_return_format === CODEBIRD_RETURNFORMAT_ARRAY;
    if ($reply === '[]') {
      switch ($this->_return_format) {
        case CODEBIRD_RETURNFORMAT_ARRAY:
          return [];
        case CODEBIRD_RETURNFORMAT_JSON:
          return '{}';
        case CODEBIRD_RETURNFORMAT_OBJECT:
          return new \stdClass;
      }
    }
    if (! $parsed = json_decode($reply, $need_array, 512, JSON_BIGINT_AS_STRING)) {
      if ($reply) {
        // assume query format
        $reply = explode('&', $reply);
        foreach ($reply as $element) {
          if (stristr($element, '=')) {
            list($key, $value) = explode('=', $element, 2);
            $parsed[$key] = $value;
          } else {
            $parsed['message'] = $element;
          }
        }
      }
      $reply = json_encode($parsed);
    }
    switch ($this->_return_format) {
      case CODEBIRD_RETURNFORMAT_ARRAY:
        return $parsed;
      case CODEBIRD_RETURNFORMAT_JSON:
        return $reply;
      case CODEBIRD_RETURNFORMAT_OBJECT:
        return (object) $parsed;
    }
    return $parsed;
  }
}

Why if the title is too long I'm getting this warning and it doesn't post on Twitter?

P.S.

I have installed PHP 5.5.9 but the problem still the same.

图片转代码服务由CSDN问答提供 功能建议

查看我的Apache错误日志文件,我检查了此警告:

   PHP警告:json_decode():选项JSON_BIGINT_AS_STRING未在第2517行的/../codebird.php中实现
   
 
 

它是指我使用的脚本 从我的博客在Twitter上自动发布。

这是有罪的功能:

  protected function _parseApiReply($ reply)
  {
 $ need_array = $ this-> _return_format === CODEBIRD_RETURNFORMAT_ARRAY; 
 if($ reply ==='[]'){
 switch($ this-> _return_format){
 case CODEBIRD_RETURNFORMAT_ARRAY:\  n return []; 
 case CODEBIRD_RETURNFORMAT_JSON:
 return'{}'; 
 case CODEBIRD_RETURNFORMAT_OBJECT:
返回new \ stdClass; 
} 
} 
 if(!$ parsed = json_decode($ reply,$  need_array,512,JSON_BIGINT_AS_STRING)){
 if($ reply){
 //假设查询格式
 $ reply = explode('&',$ reply); 
  foreach($ reply as $ element){
 if(stristr($ element,'=')){
 list($ key,$ value)= explode('=',$ element,2); 
 $ 解析[$ key] = $ value; 
} else {
 $ parsed ['message'] = $ element; 
} 
} 
} 
 $ reply = json_encode($ parsed); 
}  
开关($ this-> _return_format){
 case CODEBIRD_RETURNFORMAT_ARRAY:
 return $ parsed; 
 case CODEBIRD_RETURNFORMAT_JSON:
 return $ reply; 
 case CODEBIRD_RETURNFORMAT_OBJECT:
 return(object)$ parsed; 
  } 
返回$ parsed; 
} 
} 
   
 
 

为什么标题太长我收到此警告并且不会发布 推特?

PS

我已经安装了 PHP 5.5.9 ,但问题仍然存在。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqi1245 2016-08-03 17:33
    已采纳

    The JSON_BIGINT_AS_STRING option has only been available since PHP 5.4. You can remove it, but if the numbers contained in your JSON response are too big they will overflow.

    Looking into this further, it appears that there were some problems with JSON's license that have resulted in Debian-based distributions not providing packages for the standard JSON extension. They replace it with a mostly-compatible version that defines a constant JSON_C_VERSION that can be checked for:

    if (defined("JSON_C_VERSION") || version_compare(PHP_VERSION, '5.4.0', '<')) {
        json_decode($reply, $need_array, 512);
    } else {
        json_decode($reply, $need_array, 512, JSON_BIGINT_AS_STRING);
    }
    

    Or, just remove the fourth parameter. I've always used Scientific Linux which is a RHEL distro, so had never come across this issue before.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题