doutuan6158 2014-02-04 06:16
浏览 54

json编码逗号失败

I have the following json response from a php file

{
    "id":"85",
    "title":"Hello,
    hello I said",
    "tags":null,
}

the correct output in the "title" should be: "title":"Hello, hello I said", bla bla bla.

Notice that the comma after the Hello.

i am using json_encode() but I still get the above result (which breaks the json).

here is my php code:

$query = mysql_query("SELECT * from songs");
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$rows[] = $r;
}

$songArray = array(
  "songs" => $rows
);

$jsonD = json_encode($songArray);

If I don't include the commas in my input everything works fine.

The code should work, there is nothing special in it.

Does anyone have any ideas why this is happening? How can I be fixed. thank you

  • 写回答

6条回答 默认 最新

  • doucezhu3570 2014-02-04 06:19
    关注

    { "id":"85", "title":"Hello, hello I said", "tags":null, }

    is invalid json. You need to remove the comma after null,

    { "id":"85", "title":"Hello, hello I said", "tags":null }

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效