๋ณธ๋ฌธ์ด ๋ฒํผ๋ก ์ฑ์์ ธ ์์ ๋ ์๋ต ๋ณธ๋ฌธ์์ BOM์ด ์ ๊ฑฐ๋์ง ์์
request({
url: url,
json: true,
strictSSL: false,
}, (error, response, data) => {
if (error) {
throw error;
}
if (response.statusCode === 200) {
// data is string instead of json deserialized object
}
})
BOM ๋ฌธ์๊ฐ ์ ๊ฑฐ๋๊ณ json ์๋ต์ด ์ง๋ ฌํ ํด์ ๋จ
JSON.parse๊ฐ ์คํจํ๊ณ ๋ฌธ์์ด์ด ๋ฐํ๋ฉ๋๋ค.
if (bufferLength) {
debug('has body', self.uri.href, bufferLength)
response.body = Buffer.concat(buffers, bufferLength)
if (self.encoding !== null) {
response.body = response.body.toString(self.encoding)
}
// `buffer` is defined in the parent scope and used in a closure it exists for the life of the Request.
// This can lead to leaky behavior if the user retains a reference to the request object.
buffers = []
bufferLength = 0
} else if (strings.length) {
// The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation.
// Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse().
if (self.encoding === 'utf8' && strings[0].length > 0 && strings[0][0] === '\uFEFF') {
strings[0] = strings[0].substring(1)
}
response.body = strings.join('')
}
์ฐ๋ฆฌ๊ฐ ๋ณผ ์ ์๋ฏ์ด BOM char๋ ๋ฒํผ ๋์ ๋ฌธ์์ด์ด ์ฌ์ฉ๋ ๋ ์ ๊ฑฐ๋ฉ๋๋ค.
ํญ์ ์๋ต ๋ณธ๋ฌธ์ ์ ๋ฆฌํ๋ ค๋ฉด else if(strings.length) ์ธ๋ถ์์ ์ฝ๋๋ฅผ ์ถ์ถํฉ๋๋ค.
swashbuckle์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ํ์ฌ ์ฌ์ฉ์ ์ง์ swagger์์ json ์๋ต ์ฝ๊ธฐ
| ์ํํธ์จ์ด | ๋ฒ์
| ---------------- | -------
| ์์ฒญ | 2.83.0
| ๋
ธ๋ | 9.3.0
| npm | 5.5.1
| ์ด์ ์ฒด์ | ์๋์ฐ 10
์์ฒญ ์ต์ ์์ encoding: 'utf8'์ ์ค์ ํ๋ฉด ์๋ต์ด ๊ตฌ๋ฌธ ๋ถ์๋ฉ๋๋ค.
์ด ๋ฌธ์ ๋ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ค๋๋ ๊ฒ์ผ๋ก ํ์๋์์ต๋๋ค. ๋ ์ด์ ํ๋์ด ์์ผ๋ฉด ํ์๋ฉ๋๋ค. ๊ทํ์ ๊ธฐ์ฌ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ด ๋ฌธ์ ๋ ๋ณด๊ณ ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๊ฒ์ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ํ์ง๋ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ด ๋ฌธ์ ๋ฅผ ์ฒ๋ฆฌํ๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์ฒญ ์ต์ ์์ encoding: 'utf8'์ ์ค์ ํ๋ฉด ์๋ต์ด ๊ตฌ๋ฌธ ๋ถ์๋ฉ๋๋ค.