floralvikings / jira-connector

NodeJS Wrapper for the Jira REST API
http://floralvikings.github.io/jira-connector/
MIT License
373 stars 180 forks source link

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

Open LveUp opened 5 years ago

LveUp commented 5 years ago
                    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 commented 4 years ago

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

MrRefactoring commented 4 years ago

It looks like it's related to #80