invalid byte 2 of 2-byte UTF-8 sequence

前端 未结 7 1930
萌比男神i
萌比男神i 2020-12-14 16:18

I am trying to parse an XML file with but ran into an error message invalid byte 2 of 2-byte UTF-8 sequence

7条回答
  •  一个人的身影
    2020-12-14 16:49

    Most commonly it's due to feeding ISO-8859-x (Latin-x, like Latin-1) but parser thinking it is getting UTF-8. Certain sequences of Latin-1 characters (two consecutive characters with accents or umlauts) form something that is invalid as UTF-8, and specifically such that based on first byte, second byte has unexpected high-order bits.

    This can easily occur when some process dumps out XML using Latin-1, but either forgets to output XML declaration (in which case XML parser must default to UTF-8, as per XML specs), or claims it's UTF-8 even when it isn't.

提交回复
热议问题