doutang7415 2013-12-25 10:05
浏览 57
已采纳

致命错误:找不到“Services_JSON”类

I try to create a very simple web application on 000webhosting, but when I try to implement this:

<?php

include_once("JSON.php");
$json = new Services_JSON();

$link = mysql_pconnect("******", "******", "******") or die("Could not connect");
mysql_select_db("******") or die("Could not select database");

$arr = array();

$rs = mysql_query("SELECT * FROM users");
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}

Echo $json->encode($arr);

?>

But I got this warning/error. Could you help me please?

Warning: include_once(JSON.php) [function.include-once]: failed to open stream: No such file or directory in /home/a1622045/public_html/index.php on line 3

Warning: include_once() [function.include]: Failed opening 'JSON.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/a1622045/public_html/index.php on line 3

Fatal error: Class 'Services_JSON' not found in /home/a1622045/public_html/index.php on line 4

  • 写回答

2条回答 默认 最新

  • duangang4001 2013-12-25 15:02
    关注

    Change this:

    Echo $json->encode($arr);
    

    to this:

    echo json_encode($arr);
    

    and remove this:

    include_once("JSON.php");
    $json = new Services_JSON();
    

    The program you are working on uses an old PEAR library, which converts JSON object notation into PHP arrays, and vice versa. However PHP has had the ability to do this natively for many years, and so your code is relying on a dependency it does not need.

    I have switched Echo to echo too - PHP keywords may work in mixed-case format, but it is a good convention to write them in lower-case, as per the manual.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?