dougu3290 2014-03-31 14:48
浏览 67
已采纳

PHP - 来自mysql的json_decode

I have an Android app, PHP page and MySql db.
The android app send a string parameter to the server, I use Gson so I know that the Json string is correct.
On server side I store that string of json as Text field.
On web client I take that field from my database and doing json_decode and receives a NULL.
Most of the site written by PHPMAKER 10 so I use it's database connection.

$result="";
$rs->MoveFirst();
if ($rs) {
    $result = $rs->fields[0];
}
$rs->Close();
$extras = json_decode($result, true);

I checked that json in Json validator and it looks fine.

Any ideas why I gets null? (maybe encoding)

EDIT: I did the following check:

echo "<script> var x = {$result}; console.log(x.length)</script>";

Chrome gave the following error:

Uncaught SyntaxError: Unexpected token ILLEGAL 

EDIT 2: If I print that string echo $result and copy that to a variable it works.

  • 写回答

2条回答 默认 最新

  • 「已注销」 2014-04-02 08:13
    关注

    I soled the problem:
    My json contained breaklines '/r' and '/r/n'.
    After removing them everything was fine.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?