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g8RnkX|n[]GshrKp_Z}ugryLg8Oq^7}{h8[~_]RnTsxn_s[z^8Wug79nTnOofLKz_7[Yi\O^8OuhMWug79nQHOxf\:wiL[9iHN;NqGx_\K_XG[hLi~^\WqNs5xNq[|_8Om_L[Rf\:w[MOmgsSm^8Wug7:Nou<Nr_6grS5f\>zNotn^7mmgriqZ8[nh7S~f]G5f\>zNn|ngLqzf8WqjMVnTnOVgL[mh7Zl[]GshrKp_XO>QHO[hLi~^\WqYLqzf5qzir[iL6qgsWGgrKxj]Suh~N;j~Ori\:oiLq{gnN;NrSt^\:s_[S6^sSohrq|iLq{gnNxNr}ugry5_]m5NotnZL}q^]SqNK[|_8Om_LZnkX|n[]GshrKp_Z}ugryIg76|^]Om^r}qh~N;j~Ori\:oiLq{gnN;NrSt^\:s_[S6^sSohrq|iLq{gnNxNr}ugry5_]m5NotnZL}q^]SqNK[|_8Om_LZnk]6ikVBB

我相信我能够提取以下JavaScript函数来解码字符串:

function handleServerReponse(a) {
        if (a.substr(0, 5) == 'I:Qc[') {
            var f = 5;
            var e = (a.substr(5) + '').split('');
            var d = [];
            for (var b = e.length - 1; b >= 0; b--) {
                d[b] = String.fromCharCode(e[b].charCodeAt(0) - f)
            }
            a = d.join('');
        }
        return a
    }

function fix_utf8(c) {
        var d = []
          , a = 0
          , b = 0
          , e = 0
          , f = 0;
        while (a < c.length) {
            b = c.charCodeAt(a);
            if (b < 128) {
                d.push(String.fromCharCode(b));
                a++
            } else {
                if (b > 191 && b < 224) {
                    e = c.charCodeAt(a + 1);
                    d.push(String.fromCharCode((b & 31) << 6 | e & 63));
                    a += 2
                } else {
                    e = c.charCodeAt(a + 1);
                    f = c.charCodeAt(a + 2);
                    d.push(String.fromCharCode((b & 15) << 12 | (e & 63) << 6 | f & 63));
                    a += 3
                }
            }
        }
        return d.join('')
    }



function base64_decode(a) {
        var e = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
        var f, j, n, l, m, h, i, d, b = 0, g = 0, k = '', c = [];
        if (!a) {
            return a
        }
        a += '';
        do {
            l = e.indexOf(a.charAt(b++));
            m = e.indexOf(a.charAt(b++));
            h = e.indexOf(a.charAt(b++));
            i = e.indexOf(a.charAt(b++));
            d = l << 18 | m << 12 | h << 6 | i;
            f = d >> 16 & 255;
            j = d >> 8 & 255;
            n = d & 255;
            if (h == 64) {
                c[g++] = String.fromCharCode(f)
            } else {
                if (i == 64) {
                    c[g++] = String.fromCharCode(f, j)
                } else {
                    c[g++] = String.fromCharCode(f, j, n)
                }
            }
        } while (b < a.length);k = c.join('');
        return k
    }

 function utf8_from_str(s) {
    for(var i=0, enc = encodeURIComponent(s), a = []; i < enc.length;) {
        if(enc[i] === '%') {
            a.push(parseInt(enc.substr(i+1, 2), 16))
            i += 3
        } else {
            a.push(enc.charCodeAt(i++))
        }
    }
    return a
}

function utf8_to_str(a) {
    for(var i=0, s=''; i<a.length; i++) {
        var h = a[i].toString(16)
        if(h.length < 2) h = '0' + h
        s += '%' + h
    }
    return decodeURIComponent(s)
}

经过不同的尝试/组合后,这就是我使用代码的方式:

var c = handleServerReponse('encoded string above');
c = base64_decode(c);
c = utf8_from_str(c);
c = utf8_to_str(c);
c = fix_utf8(c);

这就是我得到的结果。如您所见,它似乎是JSON字符串,但未正确解码。关于如何正确解码的任何提示?

{"resultHȔ뜙\힒ٞHLMNM苈㛛隝YHLLMˌ펌C""¤ƗF燖FR#⠈蠄؈䄈ɍхє訉
谉%AL計؀Ӣ,"City":"LA JOLLA","ZipFive":"9201ȋٙ霒#⣓Sc4䄄TĔt傄E""¥&F$䂣⥃䣓tR"¥G熒#⥴e""¥W6T6憕F熆R#⥶榶ƒf層ቕͥᕹ픈ɉ䈎茈눐蝚#⣢"¥7gB#⣢ÃS2"¤ƷE6禒#⣓Ró"¤ƷE6禔
ɕ̈舀萈ɥᲂuilt":"1966","isS﹓憖洷$W斗B#⤦⢂$dң⢃"ÓcÃ"¤fᅉᕕŕ呤計и,024","inForeclo]\鈎蓛ȋ㘜ݕ蛜ٙ\䙴FFT�ᥑr":"Aug 2012","LastTransferXǖR#⢃ósÓ"¦紆緆VDf祶ƒ#⤦⢂$Ɨ7D詬顉梺"/v1/properties/P19B107E/lists"},"Cont`ݜȎ陈݌Kܜ뜙\횙\˔NP쌍ыܙ\웛싙ꖆG2䷦W'f旲'҂%淆噥ៈꜙb#⢷c燦熗'F旲僓䣓tR熆熷7fᕽ̉䰉U]Ʌᕱ幭퉕�͕ɕ̈鬉镹푥�艍ᅹ핍Ҙܚ\[ۈ눛淆W炣⥆ƅe UpgraH圙ܘYS浇&綖7F涤詬陕鍑ﮢ:"changeSubscriptkۈ눛[ꝙ^X\و\ܘYH圙ܘFTƖ洖禕ѵ幑酱卥̈鬉鞣tion":"chc陔ݘ옜ꜝ[ۈ눛[ꝙ^X\و\ܘYH圙ܘYS[ꐛۜ\蘛\Ȏ�F涢#⦶湝单鍍ɥQ彸谉᥹푕ᐈ艁ᕅ͔ᕁ퉅ᔉ嵵䀀

0 个答案:

没有答案