ajax传含有中文的json给php,如果json中的key是中文,php部分获取的结果不对

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回答
大家讲道理
1个月前大家讲道理

光阴似箭催人老,日月如移越少年。

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

赞同00个回复