pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="z5lnp1r" 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="pphhdvv" 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的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  如果我在 json 字符串中有一個 unicode 字符,它將無法解碼.我不知道為什么因為 json.org 說一個字符串可以包含: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 對字符串進行解碼,但是該字符會被破壞成其他東西.這是結果數組的 print_r 的結果.兩個字符.

                  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
                  

                  當我再次對數組進行編碼時,字符轉義為 ascii,根據 json 規范這是正確的:

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

                  "Tag"=>"Odu00f3metro"
                  

                  有什么辦法可以解除這種情況嗎?json_encode 沒有提供這樣的選項,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 有一個 unescaped_unicode 選項.但是,它沒有按預期工作.哦,該死的,它僅適用于 php 5.4.我將不得不使用一些正則表達式,因為我只有 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.

                  這就是我這么認為的原因:

                  Here's why I think so:

                  • json_encode 在您通過 utf8_encode 運行輸入字符串后生成可解析的輸出,該字符串從 ISO 8859-1 轉換為 UTF-8.
                  • 你確實說過在執行 utf8_encode 之后使用 print_r 時你得到了錯位"的輸出,但你得到的錯位輸出實際上正是嘗試解析會發生的情況作為 ISO 8859-1 的 UTF-8 文本(在 UTF-8 中 ó 是 x63xb3,但在 ISO 8859-1 中該序列是 ?3.
                  • 您的 htmlentities hackaround 解決方案奏效了.htmlentities 需要知道輸入字符串的編碼才能正常工作.如果您不指定,則假定為 ISO 8859-1.(html_entity_decode,令人困惑的是,默認為 UTF-8,因此您的方法具有從 ISO 8859-1 轉換為 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 轉義,但正如您所指出的,這是有效的 JSON.

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

                  因此,您似乎需要配置與 Postgres 的連接,以便它為您提供 UTF-8 字符串.PHP 手冊表明您可以通過將 options='--client_encoding=UTF8' 附加到連接字符串來執行此操作.當前存儲在數據庫中的數據也有可能采用錯誤的編碼.(您可以簡單地使用 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).

                  最后,正如另一個答案所指出的,您確實需要確保使用 HTTP 標頭或其他方式聲明正確的字符集(當然,這個特定問題可能只是您所做的環境的產物您的 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).

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

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                  • <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="5vjt5jd" 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>
                          • 主站蜘蛛池模板: 岛津二手液相色谱仪,岛津10A液相,安捷伦二手液相,安捷伦1100液相-杭州森尼欧科学仪器有限公司 | 成都茶楼装修公司 - 会所设计/KTV装修 - 成都朗煜装饰公司 | 考勤系统_人事考勤管理系统_本地部署BS考勤系统_考勤软件_天时考勤管理专家 | 成都网站建设制作_高端网站设计公司「做网站送优化推广」 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 黑龙江京科脑康医院-哈尔滨精神病医院哪家好_哈尔滨精神科医院排名_黑龙江精神心理病专科医院 | 网站建设-高端品牌网站设计制作一站式定制_杭州APP/微信小程序开发运营-鼎易科技 | 深圳富泰鑫五金_五金冲压件加工_五金配件加工_精密零件加工厂 | 四川实木门_成都实木门 - 蓬溪聚成门业有限公司 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器 | 发电机组|柴油发电机组-批发,上柴,玉柴,潍柴,康明斯柴油发电机厂家直销 | 骨密度检测仪_骨密度分析仪_骨密度仪_动脉硬化检测仪专业生产厂家【品源医疗】 | 一技任务网_有一技之长,就来技术任务网| 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 机房监控|动环监控|动力环境监控系统方案产品定制厂家 - 迈世OMARA | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 安徽合肥项目申报咨询公司_安徽合肥高新企业项目申报_安徽省科技项目申报代理 | 上海佳武自动化科技有限公司| 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 单柱拉力机-橡胶冲片机-哑铃裁刀-江都轩宇试验机械厂 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 | 台式恒温摇床价格_大容量恒温摇床厂家-上海量壹科学仪器有限公司 | 通辽信息港 - 免费发布房产、招聘、求职、二手、商铺等信息 www.tlxxg.net | 交联度测试仪-湿漏电流测试仪-双85恒温恒湿试验箱-常州市科迈实验仪器有限公司 | 辽宁资质代办_辽宁建筑资质办理_辽宁建筑资质延期升级_辽宁中杭资质代办 | 防爆暖风机_防爆电暖器_防爆电暖风机_防爆电热油汀_南阳市中通智能科技集团有限公司 | 柔软云母板-硬质-水位计云母片组件-首页-武汉长丰云母绝缘材料有限公司 | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 工业铝型材-铝合金电机壳-铝排-气动执行器-山东永恒能源集团有限公司 | LED投光灯-工矿灯-led路灯头-工业灯具 - 山东普瑞斯照明科技有限公司 | 水厂自动化-水厂控制系统-泵站自动化|控制系统-闸门自动化控制-济南华通中控科技有限公司 | 睿婕轻钢别墅_钢结构别墅_厂家设计施工报价 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 曙光腾达官网-天津脚手架租赁-木板架出租-移动门式脚手架租赁「免费搭设」 | 济南铝方通-济南铝方通价格-济南方通厂家-山东鲁方通建材有限公司 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 |