Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

body.join('')返回中文偶尔会出现乱码 #194

Open
LveUp opened this issue Oct 16, 2019 · 2 comments
Open

body.join('')返回中文偶尔会出现乱码 #194

LveUp opened this issue Oct 16, 2019 · 2 comments

Comments

@LveUp
Copy link

LveUp commented Oct 16, 2019

                    response.on('end', function () {
                        //新的解析方式
                        const StringDecoder = require('string_decoder').StringDecoder;
                        const decoder = new StringDecoder('utf8');
                        let newResult = '';
                        for (let i = 0; i < body.length; i++) {
                            let str = decoder.write(body[i]);
                            newResult += str
                        }
                        console.log('============new result==========', newResult);
                       
                        //旧的解析方式
                        var result = body.join('');

                        // Parsing JSON
                        if (result[0] === '[' || result[0] === '{') {
                            try {
                                console.log('============result==========', result);

                                result = JSON.parse(result);
                            } catch (e) {
                                // nothing to do
                            }
                        }

//newResult:
...
"name": "问题类型",
...

//result:
...
"name": "��题类型",
...

@MrRefactoring
Copy link
Collaborator

Hi, @LveUp! I need help from more experienced members, @floralvikings what do you think about this?

@MrRefactoring
Copy link
Collaborator

It looks like it's related to #80

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants