ajax传含有中文的json给php,如果json中的key是中文,php部分获取的结果不对
代言
代言 2017-01-09 17:47:01
0
1
952

ajax传含有中文的json给php,如果json中的key是中文,php部分获取的结果不对,key是英文,value是中文就没问题

这是$.ajax传给php的json串

  [
        {
            "user": {
                "user1": "user1"
            },
            "tab": {
                "表名": "表名"
            },
            "col": {
                "列名": "列名"
            },
            "isdmptab": "0",
            "lderrset": "stopld"
        },
        {
            "user": {
                "user1": "user1"
            },
            "tab": {
                "表名": "表名"
            },
            "col": {
                "列名": "列名"
            },
            "isdmptab": "0",
            "lderrset": "stopld"
        },
        {
            "user": {
                "user1": "user1"
            },
            "tab": {
                "表名": "表名"
            },
            "col": {
                "列名": "列名"
            },
            "isdmptab": "0",
            "lderrset": "stopld"
        },
        {
            "user": {
                "user1": "user1"
            },
            "tab": {
                "表名": "表名"
            },
            "col": {
                "列名": "列名"
            },
            "isdmptab": "0",
            "lderrset": "stopld"
        },
        {
            "user": {
                "user2": "user2"
            },
            "tab": {
                "表名": "表名"
            },
            "col": {
                "列名": "列名"
            },
            "isdmptab": "0",
            "lderrset": "stopld"
        }
    ]


这是php部分$_POST['tabmap']的输出
中文部分 结果不对

Array
(
    [0] => Array
        (
            [user] => Array
                (
                    [user1] => user1
                )

            [tab] => Array
                (
                    [0] => 表名
                )

            [col] => Array
                (
                    [0] => 列名
                )

            [isdmptab] => 0
            [lderrset] => stopld
        )

    [1] => Array
        (
            [user] => Array
                (
                    [user1] => user1
                )

            [tab] => Array
                (
                    [0] => 表名
                )

            [col] => Array
                (
                    [0] => 列名
                )

            [isdmptab] => 0
            [lderrset] => stopld
        )

    [2] => Array
        (
            [user] => Array
                (
                    [user1] => user1
                )

            [tab] => Array
                (
                    [0] => 表名
                )

            [col] => Array
                (
                    [0] => 列名
                )

            [isdmptab] => 0
            [lderrset] => stopld
        )

    [3] => Array
        (
            [user] => Array
                (
                    [user1] => user1
                )

            [tab] => Array
                (
                    [0] => 表名
                )

            [col] => Array
                (
                    [0] => 列名
                )

            [isdmptab] => 0
            [lderrset] => stopld
        )

    [4] => Array
        (
            [user] => Array
                (
                    [user2] => user2
                )

            [tab] => Array
                (
                    [0] => 表名
                )

            [col] => Array
                (
                    [0] => 列名
                )

            [isdmptab] => 0
            [lderrset] => stopld
        )

)

文件是utf-8编码

如果key是中文就不行,如果key不是中文就不出问题


代言
代言

全部回复(1)
大家讲道理

刚才是不是已经问过这个问题了?刚才是因为编码原因是吧!那你现在吧你的文件编码和代码编码,还有接收的需要转换的都设置成urf-8试试看呢!

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!