php的datatables和json格式化错误 [英] datatables and json formatting error with php

查看:141
本文介绍了php的datatables和json格式化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据表和php有一些困难。我正在以下列格式回显json:



{iTotalRecords:10,iTotalDisplayRecords:10,aaData:[[1, 15,1,长描述长描述长描述,2012-02-25 00:00:00),[1,15,1长描述长描述,2012-02-25 00:18:59] ...]



哪个inst工作与我的dataTable,但验证后以下在jsonlint.com/中,我得到下面的格式化版本:

  {
iTotalRecords:10,
iTotalDisplayRecords:10,
aaData:[
[
1,
15,
1,
长描述长描述长描述,
2012-02-25 00:18:59
],
...

]
}

当我将它放在一个txt文件中时,它加载很好。我也注意到,在长描述部分添加换行符,即使在上面也没有。我的猜测是,线条破坏了json的格式,但是如何在PHP脚本中避免这种情况,因为一切都是被包装的?我在我的回音码中尝试过,但似乎没有创建一个换行符。

解决方案

我的一个数据库值似乎是一个问题,它开始于一个新的行,这导致格式的json不正确。


HI im having a little difficulty with dataTables and php. I'm echoing out json in the format below:

{"iTotalRecords":10,"iTotalDisplayRecords":10,"aaData":[[ "1", "15","1","long description long description long description long description"," 2012-02-25 00:00:00"],[ "1", "15","1","long description long description long description long description"," 2012-02-25 00:18:59"] ... ] }

Which inst working with my dataTable, However after validating the above in jsonlint.com/, i get the well formated version below:

   {
            "iTotalRecords": 10,
            "iTotalDisplayRecords": 10,
            "aaData": [
                [
                    "1",
                    "15",
                    "1",
                    "long description long description long description long description",
                    "2012-02-25 00:18:59"
                ],
        ...

            ]
        }

When I put this in a txt file it loads just fine. I also noticed that adding a line break in the "long description" part, it also doesn't work even with the one above. My guess is that the line break is messing with the format of the json, but how can I avoid this in my php script since everything is being word wrapped? I've tried \n in my echo code but it doesnt seem to create a newline.

解决方案

There seemsed to be an issue with one of my database values, it was starting on a new line, which cause the format of the json to be incorrect.

这篇关于php的datatables和json格式化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆