久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='uTtPR'><style id='uTtPR'><dir id='uTtPR'><q id='uTtPR'></q></dir></style></legend>
    <tfoot id='uTtPR'></tfoot>
    • <bdo id='uTtPR'></bdo><ul id='uTtPR'></ul>

    <small id='uTtPR'></small><noframes id='uTtPR'>

      1. <i id='uTtPR'><tr id='uTtPR'><dt id='uTtPR'><q id='uTtPR'><span id='uTtPR'><b id='uTtPR'><form id='uTtPR'><ins id='uTtPR'></ins><ul id='uTtPR'></ul><sub id='uTtPR'></sub></form><legend id='uTtPR'></legend><bdo id='uTtPR'><pre id='uTtPR'><center id='uTtPR'></center></pre></bdo></b><th id='uTtPR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uTtPR'><tfoot id='uTtPR'></tfoot><dl id='uTtPR'><fieldset id='uTtPR'></fieldset></dl></div>

        PHP用unicode字符解碼和編碼json

        PHP decoding and encoding json with unicode characters(PHP用unicode字符解碼和編碼json)
          <tbody id='9oGP4'></tbody>

          • <tfoot id='9oGP4'></tfoot>
            <i id='9oGP4'><tr id='9oGP4'><dt id='9oGP4'><q id='9oGP4'><span id='9oGP4'><b id='9oGP4'><form id='9oGP4'><ins id='9oGP4'></ins><ul id='9oGP4'></ul><sub id='9oGP4'></sub></form><legend id='9oGP4'></legend><bdo id='9oGP4'><pre id='9oGP4'><center id='9oGP4'></center></pre></bdo></b><th id='9oGP4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9oGP4'><tfoot id='9oGP4'></tfoot><dl id='9oGP4'><fieldset id='9oGP4'></fieldset></dl></div>

                <small id='9oGP4'></small><noframes id='9oGP4'>

                  <bdo id='9oGP4'></bdo><ul id='9oGP4'></ul>
                  <legend id='9oGP4'><style id='9oGP4'><dir id='9oGP4'><q id='9oGP4'></q></dir></style></legend>
                  本文介紹了PHP用unicode字符解碼和編碼json的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一些 json 我需要解碼、更改然后編碼,而不會(huì)弄亂任何字符.

                  I have some json I need to decode, alter and then encode without messing up any characters.

                  如果我在 json 字符串中有一個(gè) unicode 字符,它將無法解碼.我不知道為什么因?yàn)?json.org 說一個(gè)字符串可以包含:any-Unicode-character-except-"-or--or- control-character.但它在要么是蟒蛇.

                  If I have a unicode character in a json string it will not decode. I'm not sure why since json.org says a string can contain: any-Unicode-character- except-"-or--or- control-character. But it doesn't work in python either.

                  {"Tag":"Odómetro"}
                  

                  我可以使用 utf8_encode 這將允許使用 json_decode 對字符串進(jìn)行解碼,但是該字符會(huì)被破壞成其他東西.這是結(jié)果數(shù)組的 print_r 的結(jié)果.兩個(gè)字符.

                  I can use utf8_encode which will allow the string to be decoded with json_decode, however the character gets mangled into something else. This is the result from a print_r of the result array. Two characters.

                  [Tag] => Od?3metro
                  

                  當(dāng)我再次對數(shù)組進(jìn)行編碼時(shí),字符轉(zhuǎn)義為 ascii,根據(jù) json 規(guī)范這是正確的:

                  When I encode the array again I the character escaped to ascii, which is correct according to the json spec:

                  "Tag"=>"Odu00f3metro"
                  

                  有什么辦法可以解除這種情況嗎?json_encode 沒有提供這樣的選項(xiàng),utf8_encode 似乎也不起作用.

                  Is there some way I can un-escape this? json_encode gives no such option, utf8_encode does not seem to work either.

                  編輯 我看到 json_encode 有一個(gè) unescaped_unicode 選項(xiàng).但是,它沒有按預(yù)期工作.哦,該死的,它僅適用于 php 5.4.我將不得不使用一些正則表達(dá)式,因?yàn)槲抑挥?5.3.

                  Edit I see there is an unescaped_unicode option for json_encode. However it's not working as expected. Oh damn, it's only on php 5.4. I will have to use some regex as I only have 5.3.

                  $json = json_encode($array, JSON_UNESCAPED_UNICODE);
                  Warning: json_encode() expects parameter 2 to be long, string ...
                  

                  推薦答案

                  從你所說的一切來看,你正在處理的原始 Odómetro 字符串似乎是用 ISO 8859 編碼的-1,不是UTF-8.

                  Judging from everything you've said, it seems like the original Odómetro string you're dealing with is encoded with ISO 8859-1, not UTF-8.

                  這就是我這么認(rèn)為的原因:

                  Here's why I think so:

                  • json_encode 在您通過 utf8_encode 運(yùn)行輸入字符串后生成可解析的輸出,該字符串從 ISO 8859-1 轉(zhuǎn)換為 UTF-8.
                  • 你確實(shí)說過在執(zhí)行 utf8_encode 之后使用 print_r 時(shí)你得到了錯(cuò)位"的輸出,但你得到的錯(cuò)位輸出實(shí)際上正是嘗試解析會(huì)發(fā)生的情況作為 ISO 8859-1 的 UTF-8 文本(在 UTF-8 中 ó 是 x63xb3,但在 ISO 8859-1 中該序列是 ?3.
                  • 您的 htmlentities hackaround 解決方案奏效了.htmlentities 需要知道輸入字符串的編碼才能正常工作.如果您不指定,則假定為 ISO 8859-1.(html_entity_decode,令人困惑的是,默認(rèn)為 UTF-8,因此您的方法具有從 ISO 8859-1 轉(zhuǎn)換為 UTF-8 的效果.)
                  • 您說您在 Python 中遇到了同樣的問題,這似乎將 PHP 排除在問題之外.
                  • json_encode produced parseable output after you ran the input string through utf8_encode, which converts from ISO 8859-1 to UTF-8.
                  • You did say that you got "mangled" output when using print_r after doing utf8_encode, but the mangled output you got is actually exactly what would happen by trying to parse UTF-8 text as ISO 8859-1 (ó is x63xb3 in UTF-8, but that sequence is ?3 in ISO 8859-1.
                  • Your htmlentities hackaround solution worked. htmlentities needs to know what the encoding of the input string to work correctly. If you don't specify one, it assumes ISO 8859-1. (html_entity_decode, confusingly, defaults to UTF-8, so your method had the effect of converting from ISO 8859-1 to UTF-8.)
                  • You said you had the same problem in Python, which would seem to exclude PHP from being the issue.

                  PHP 將使用 uXXXX 轉(zhuǎn)義,但正如您所指出的,這是有效的 JSON.

                  PHP will use the uXXXX escaping, but as you noted, this is valid JSON.

                  因此,您似乎需要配置與 Postgres 的連接,以便它為您提供 UTF-8 字符串.PHP 手冊表明您可以通過將 options='--client_encoding=UTF8' 附加到連接字符串來執(zhí)行此操作.當(dāng)前存儲在數(shù)據(jù)庫中的數(shù)據(jù)也有可能采用錯(cuò)誤的編碼.(您可以簡單地使用 utf8_encode,但這將僅支持屬于 ISO 8859-1 的字符.

                  So, it seems like you need to configure your connection to Postgres so that it will give you UTF-8 strings. The PHP manual indicates you'd do this by appending options='--client_encoding=UTF8' to the connection string. There's also the possibility that the data currently stored in the database is in the wrong encoding. (You could simply use utf8_encode, but this will only support characters that are part of ISO 8859-1).

                  最后,正如另一個(gè)答案所指出的,您確實(shí)需要確保使用 HTTP 標(biāo)頭或其他方式聲明正確的字符集(當(dāng)然,這個(gè)特定問題可能只是您所做的環(huán)境的產(chǎn)物您的 print_r 測試).

                  Finally, as another answer noted, you do need to make sure that you're declaring the proper charset, with an HTTP header or otherwise (of course, this particular issue might have just been an artifact of the environment where you did your print_r testing).

                  這篇關(guān)于PHP用unicode字符解碼和編碼json的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)
                  • <tfoot id='G5uL6'></tfoot>

                    1. <legend id='G5uL6'><style id='G5uL6'><dir id='G5uL6'><q id='G5uL6'></q></dir></style></legend>
                      <i id='G5uL6'><tr id='G5uL6'><dt id='G5uL6'><q id='G5uL6'><span id='G5uL6'><b id='G5uL6'><form id='G5uL6'><ins id='G5uL6'></ins><ul id='G5uL6'></ul><sub id='G5uL6'></sub></form><legend id='G5uL6'></legend><bdo id='G5uL6'><pre id='G5uL6'><center id='G5uL6'></center></pre></bdo></b><th id='G5uL6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G5uL6'><tfoot id='G5uL6'></tfoot><dl id='G5uL6'><fieldset id='G5uL6'></fieldset></dl></div>
                        <tbody id='G5uL6'></tbody>

                        <small id='G5uL6'></small><noframes id='G5uL6'>

                          • <bdo id='G5uL6'></bdo><ul id='G5uL6'></ul>
                          • 主站蜘蛛池模板: 蜜桃视频一区二区三区 | 农夫在线精品视频免费观看 | 国产成人av在线 | 日韩中文字幕在线观看 | 99久久婷婷国产精品综合 | 波多野结衣亚洲 | 一区二区日本 | 91久久久久久久久久久久久 | 视频1区2区 | 国产精品视频观看 | 欧美9999| 中文字幕的av | 一区二区三区欧美 | 麻豆久久久9性大片 | 野狼在线社区2017入口 | 久久电影一区 | 日韩欧美国产一区二区 | www.久草.com | 亚洲视频一区在线观看 | 一区二区日韩 | 日韩国产在线 | 久久精品亚洲精品国产欧美 | 青青艹在线视频 | 91亚洲国产精品 | www.亚洲| 国产在线一区二区三区 | 日韩a在线观看 | 韩日一区二区 | 亚洲午夜精品 | 欧美激情久久久 | 91久久国产精品 | 欧美一区二区三区在线看 | 亚洲精品无 | 中文字幕av高清 | 狠狠的操 | 99精品网| 91久久国产综合久久 | www久久99| 国产激情一区二区三区 | 欧洲在线视频 | 中文字幕在线看人 |