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

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不是中文就不出问题


代言
代言

répondre à tous(1)
大家讲道理

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

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!