我试图从谷歌地图请求中获取一些数据;它返回了以下数据。它以某种方式以 'b' 字符开头:
b'{
\n "destination_addresses" : [ "Toronto, ON, Canada" ],
\n "origin_addresses" : [ "Ottawa, ON, Canada" ],
\n "rows" : [\n {
\n "elements" : [\n {
\n "distance" : {
\n "text" : "450 km",
\n "value" : 449678\n
},
\n "duration" : {
\n "text" : "4 hours 14 mins",
\n "value" : 15229\n
},
\n "status" : "OK"\n
}\n ]\n
}\n ],
\n "status" : "OK"\n
}\n'
Run Code Online (Sandbox Code Playgroud)
然后我试图从数据中获取一个值,它因为开头的 'b' 而出错。如果我删除'b',它工作正常:
response = str(urllib.request.urlopen(url).read())
result …Run Code Online (Sandbox Code Playgroud)