python - Replace \b in json -
this question has answer here:
i'm receiving json file begins : 'b\'{ "key" : .... i'm attempting remove 'b\' part of string it's not valid json.
the json read using :
import urllib.request link = "http://www...." urllib.request.urlopen(link) url: s = str(url.read()) my code replace : replace('\'b\'', '') string 'b\'{ "key" : .... remains instead of { "key" : ....
attempting recreate issue excluding json string :
mystr = ' b\'{ ' mystr.replace(' b\'{ ', '') successfully replaces ' ' output.
you adding b calling str() on data get. don't that.
if need convert string, should decode instead:
s = url.read().decode('utf-8') but in fact can pass bytestring directly json.loads().
Comments
Post a Comment