简体   繁体   中英

json to php as utf-8 from jquery

I wanted to know how I can make a jQuery post with the JSON set as UTF-8. Right now this is my JSON that I'm sending to testimage.php . Would I have to do this on the client side? server side with PHP ( json_decode() )? Both?

This is what I want to post:

{
    "ff": "news-gothic-std",
    "a": "right",
    "s": 22,
    "words": [{
        "t": "trioSkincare's",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }, {
        "t": " 9th",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }, {
        "t": " Anniversary",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }, {
        "t": "John   ",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }, {
        "t": " Smith",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }, {
        "t": "\n",
        "c": "#99cccc",
        "fs": "normal",
        "fw": "700"
    }],
    "w": 277,
    "h": 46
}

First thing make sure your page has:

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

this will make all the data posted as JSON utf-8. And if you are going to store that data in a table make sure that that tables Collation is set to utf8_general_ci

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM