使用python3解析以下JsOn

时间:2018-09-18 16:17:26

标签: python-3.x web-scraping scrapy

请帮助我从python中的以下json获取gRecaptchaResponse密钥

+----------+--------------+-------------------+------------------------+
| user_id  |   user_name  |  user_created_by  |  user_created_by_name  |
+----------+--------------+-------------------+------------------------+
|    3     |     Paul     |        2          |         NULL           |
+----------+--------------+-------------------+------------------------+

2 个答案:

答案 0 :(得分:1)

resp = {'errorId': 0, 'status': 'ready', 'solution': {'gRecaptchaResponse': '03030359652SF_JNFDjddfjkjDJFKLjfds+5d6sa5d+6S56C562CS+5sc9SC262jfdsjfJDF'}, 'cost': '0.112200', 'createTime': 1537281783, 'endTime': 1537281806, 'solveCount': 0}

#for key
print(list(resp['solution'].keys())[0])

#for value
print(resp['solution']['gRecaptchaResponse'])

答案 1 :(得分:0)

您可以尝试一下:

json_data = {'errorId': 0, 'status': 'ready', 'solution': {'gRecaptchaResponse': '03030359652SF_JNFDjddfjkjDJFKLjfds+5d6sa5d+6S56C562CS+5sc9SC262jfdsjfJDF'}, 'cost': '0.112200', 'createTime': 1537281783, 'endTime': 1537281806, 'solveCount': 0}

g_key = json_data['solution']['gRecaptchaResponse']