我在 python 3 中使用 foursquare 库并尝试将我的查询(一个 python 字典转换为 json 并对其进行编码
im working with foursquare library in python 3 and trying to convert my query which is a python dictionary into json and encode it
我在 python 3 中使用 foursquare 库并尝试将我的查询(一个 python 字典转换为 json 并编码数据:
#query is a dict
query= client.venues.search(params={'categoryId':catid,'radius':radius,'ll': locus})
然后:
for i in query:
jsonx=json.dumps(query[i])
pp.pprint(jsonx.encode('utf-8'))
但我无法获取波斯语字符
输出是这样的:
b'[{"id": "578e4b21498e80bd308334bb", "name": "Shahid Kazemi Stadium | \u0'
b'648\u0631\u0632\u0634\u06af\u0627\u0647 \u0634\u0647\u06cc\u062f'
b' \u06a9\u0627\u0638\u0645\u06cc (\u0648\u0631\u0632\u0634\u06af\'
b'u0627\u0647 \u0634\u0647\u06cc\u062f \u06a9\u0627\u0638\u0645\u0'
b'6cc)", "location": {"address": "End of Navab Hwy.", "crossStreet": "West Sha'
b'ghayegh Blvd.", "lat": 35.61106, "lng": 51.360404, "labeledLatLngs": [{"labe'
b'l": "display", "lat": 35.61106, "lng": 51.360404}], "distance": 3391, "cc": '
b'"IR", "city": "\u062a\u0647\u0631\u0627\u0646", "state": "\u062a\u06'
b'47\u0631\u0627\u0646", "country": "\u0627\u06cc\u0631\u0627\u0646", '
b'"formattedAddress": ["End of Navab Hwy. (West Shaghayegh Blvd.)", "\u062'
b'a\u0647\u0631\u0627\u0646, \u062a\u0647\u0631\u0627\u0646", "\u0'
b'627\u06cc\u0631\u0627\u0646"]}, "categories": [{"id": "4bf58dd8d48988d18'
b'8941735", "name": "Soccer Stadium", "pluralName": "Soccer Stadiums", "shortN'
b'ame": "Soccer", "icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/a'
b'rts_entertainment/stadium_soccer_", "suffix": ".png"}, "primary": true}], "r'
b'eferralId": "v-1576913650", "hasPerk": false}, {"id": "5722fdc2498ee138baea8'
尝试去理解查询的真实类型,因为很可能不是字典,有以下几点:
print(type(query))
不明白为什么会出现FOR循环
jsonx=json.dumps(query)
pp.pprint(jsonx)
我模拟了一个普通的字典,似乎工作正常:
import json
import pprint as pp
query = {"key1" : 1, "key2" : 2}
jsonx=json.dumps(query, ensure_ascii=False)
pp.pprint(jsonx)
输出:
'{"key1": 1, "key2": 2}'
我在 python 3 中使用 foursquare 库并尝试将我的查询(一个 python 字典转换为 json 并编码数据:
#query is a dict
query= client.venues.search(params={'categoryId':catid,'radius':radius,'ll': locus})
然后:
for i in query:
jsonx=json.dumps(query[i])
pp.pprint(jsonx.encode('utf-8'))
但我无法获取波斯语字符 输出是这样的:
b'[{"id": "578e4b21498e80bd308334bb", "name": "Shahid Kazemi Stadium | \u0'
b'648\u0631\u0632\u0634\u06af\u0627\u0647 \u0634\u0647\u06cc\u062f'
b' \u06a9\u0627\u0638\u0645\u06cc (\u0648\u0631\u0632\u0634\u06af\'
b'u0627\u0647 \u0634\u0647\u06cc\u062f \u06a9\u0627\u0638\u0645\u0'
b'6cc)", "location": {"address": "End of Navab Hwy.", "crossStreet": "West Sha'
b'ghayegh Blvd.", "lat": 35.61106, "lng": 51.360404, "labeledLatLngs": [{"labe'
b'l": "display", "lat": 35.61106, "lng": 51.360404}], "distance": 3391, "cc": '
b'"IR", "city": "\u062a\u0647\u0631\u0627\u0646", "state": "\u062a\u06'
b'47\u0631\u0627\u0646", "country": "\u0627\u06cc\u0631\u0627\u0646", '
b'"formattedAddress": ["End of Navab Hwy. (West Shaghayegh Blvd.)", "\u062'
b'a\u0647\u0631\u0627\u0646, \u062a\u0647\u0631\u0627\u0646", "\u0'
b'627\u06cc\u0631\u0627\u0646"]}, "categories": [{"id": "4bf58dd8d48988d18'
b'8941735", "name": "Soccer Stadium", "pluralName": "Soccer Stadiums", "shortN'
b'ame": "Soccer", "icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/a'
b'rts_entertainment/stadium_soccer_", "suffix": ".png"}, "primary": true}], "r'
b'eferralId": "v-1576913650", "hasPerk": false}, {"id": "5722fdc2498ee138baea8'
尝试去理解查询的真实类型,因为很可能不是字典,有以下几点:
print(type(query))
不明白为什么会出现FOR循环
jsonx=json.dumps(query)
pp.pprint(jsonx)
我模拟了一个普通的字典,似乎工作正常:
import json
import pprint as pp
query = {"key1" : 1, "key2" : 2}
jsonx=json.dumps(query, ensure_ascii=False)
pp.pprint(jsonx)
输出:
'{"key1": 1, "key2": 2}'