鍍金池/ 問(wèn)答/HTML/ 后臺(tái)返回的中文數(shù)據(jù)是亂碼,如何解析成正常字符?

后臺(tái)返回的中文數(shù)據(jù)是亂碼,如何解析成正常字符?

今天看項(xiàng)目發(fā)現(xiàn)個(gè)中文亂碼,

clipboard.png
代碼也只是很簡(jiǎn)單的綁定:

clipboard.png
看了下返回?cái)?shù)據(jù),返回?cái)?shù)據(jù)也是亂碼:

clipboard.png

但是他在www.json.cn 網(wǎng)站上卻可以正確解析,

clipboard.png

請(qǐng)問(wèn)為啥www.json.cn上面可以正確解析?
還有這個(gè)亂碼要怎么處理呢,使用jSON.parse 無(wú)法處理,還是亂碼。
測(cè)試數(shù)據(jù)如下:

{"resultType":0,"message":null,"flag":null,"result":"{\"ABORTION_NUM\":\"\",\"ASK_DOCTOR\":\"\",\"ASK_OTHER\":\"\",\"BIRTHDAY\":\"1979/9/5 0:00:00\",\"CARD_NO\":\"A20140513123\",\"COUNTRY\":\"1\",\"DAUGHTER_HEREDITARY\":\"\",\"DAUGHTER_NUM\":\"\",\"EDUCATION\":\"\",\"FAMILY_ILLNESS_BLIND\":\"\",\"FAMILY_ILLNESS_DEAF\":\"\",\"FAMILY_ILLNESS_DIABETES\":\"\",\"FAMILY_ILLNESS_HEART\":\"\",\"FAMILY_ILLNESS_HEMOPHILIA\":\"\",\"FAMILY_ILLNESS_INNATE\":\"\",\"FAMILY_ILLNESS_MUTE\":\"\",\"FAMILY_ILLNESS_NONE\":\"\",\"FAMILY_ILLNESS_OTHER\":\"\",\"FAMILY_ILLNESS_OTHER_INFO\":\"\",\"FAMILY_ILLNESS_VENEREAL\":\"\",\"FORMER_ILLNESS_DIABETES\":\"\",\"FORMER_ILLNESS_FALING\":\"\",\"FORMER_ILLNESS_HEART\":\"\",\"FORMER_ILLNESS_HYPERTENSION\":\"\",\"FORMER_ILLNESS_INNATE\":\"\",\"FORMER_ILLNESS_LIVER\":\"\",\"FORMER_ILLNESS_LUNACY\":\"\",\"FORMER_ILLNESS_LUNG\":\"\",\"FORMER_ILLNESS_NONE\":\"\",\"FORMER_ILLNESS_OTHER\":\"\",\"FORMER_ILLNESS_OTHER_INFO\":\"\",\"FORMER_ILLNESS_TESTA\":\"\",\"FORMER_ILLNESS_URINARY\":\"\",\"FORMER_ILLNESS_VENEREAL\":\"\",\"FULL_TERM_NUM\":\"\",\"HEALTH_NO\":\"\",\"HYGIENE_PROFESSION\":\"\",\"ID\":\"6368\",\"IDENTITY_CARD_NO\":\"350203197909054089\",\"IDENTITY_TYPE\":\"1\",\"ILLNESS_RELATION\":\"\",\"INTERMARRY\":\"\",\"INTERMARRY_GRANDPARENT\":\"\",\"IS_EDIT_FLAG\":\"0\",\"KIN\":\"\",\"KIN_OTHER_INFO\":\"\",\"LOVER_NAME\":\"\",\"MARITAL_HISTORY\":\"\",\"MARITAL_NO\":\"\",\"MEDICAL_DATE\":\"\",\"MENSES_AGE\":\"\",\"MENSES_LAST\":\"\",\"MENSES_PERIOD\":\"\",\"MENSTRUAL_BLEEDING\":\"\",\"MENSTRUAL_COLIC\":\"\",\"MENSTRU_DATE\":\"\",\"MISCARRY_NUM\":\"\",\"NATION\":\"\",\"OPERATE_ILLNESS\":\"\",\"OPERATE_ILLNESS_INFO\":\"\",\"PRESENT_ILLNESS\":\"\",\"PRESENT_ILLNESS_INFO\":\"\",\"SICK_ADDRESS\":\"软件园2期88811111\",\"SICK_CITY\":\"\",\"SICK_COUNTRY\":\"\",\"SICK_COUNTY\":\"\",\"SICK_HOUSEHOLD_ADDRESS\":\"\",\"SICK_HOUSEHOLD_CITY\":\"\",\"SICK_HOUSEHOLD_COUNTRY\":\"\",\"SICK_HOUSEHOLD_COUNTY\":\"\",\"SICK_HOUSEHOLD_PROVINCE\":\"\",\"SICK_HOUSEHOLD_VILLAGE\":\"\",\"SICK_NAME\":\"陶丽文\",\"SICK_PHONE\":\"18060031825\",\"SICK_POSTALCODE\":\"\",\"SICK_PROVINCE\":\"\",\"SICK_SEX\":\"2\",\"SICK_VILLAGE\":\"\",\"SICK_WORK_COMPANY\":\"\",\"SON_HEREDITARY\":\"\",\"SON_NUM\":\"\"}"}
回答
編輯回答
蔚藍(lán)色

你的這個(gè)問(wèn)題挺有趣,我先根據(jù)這個(gè)漢字編碼查,我用js utf8轉(zhuǎn)漢字轉(zhuǎn)不過(guò)來(lái),后來(lái)研究了一下你發(fā)的這個(gè)json解釋的網(wǎng)站,他只是jQuery append了一下<span>&#38518;&#20029;&#25991;</span>就轉(zhuǎn)成了漢字,這個(gè)很神奇,
然后我試了一下原生js dom節(jié)點(diǎn)innerHTML插入這個(gè)也可以,也就是插入節(jié)點(diǎn)時(shí)就直接轉(zhuǎn)成漢字了,原理不明
然后你再innerText拾取的就是轉(zhuǎn)換后的

2018年9月5日 22:34
編輯回答
青裙

看看是不是你的元信息的問(wèn)題 也就是 charset:utg-8 ,而json.parse是將字符串轉(zhuǎn)對(duì)象的,如果有亂碼你看看是不是請(qǐng)求服務(wù)器的數(shù)據(jù)本身有問(wèn)題 也可以看看 請(qǐng)求對(duì)象.status == ?

2018年2月1日 01:30