How to include pictures bytes to a JSON with python? (encoding issue)

前端 未结 2 1040
春和景丽
春和景丽 2020-12-06 12:58

I would like to include picture bytes into a JSON, but I struggle with a encoding issue:

import urllib
import json

data = urllib.urlopen(\'https://www.pytho         


        
2条回答
  •  感动是毒
    2020-12-06 13:27

    The best solution that comes to my mind for this situation, space-wise, is base85 encoding which represents four bytes as five characters. Also you could also map every byte to the corresponding character in U+0000-U+00FF format and then dump it in the json. But still, those could be overkill methods for this and base64, ease-wise, would be the winner.

提交回复
热议问题