-3

I have this JSON content:

{'status': '1', 'message': 'OK',
'result': {'LastBlock': '14934113', 'SafeGasPrice': '119', 'ProposeGasPrice': '119', 'FastGasPrice': '119',
'suggestBaseFee': '118.174590189', 'gasUsedRatio': '0.025821954106323,0.354559890356924,0.173050329701518,0.340210087647076,0.0269005272339711'}}

How I can get strings from 'result'? I want to get 'SafeGasPrice'

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

I first get the values from result: gas_unit_price = gas_unit_price.json()["result"] Second I get the string I need: gas_unit_price = gas_unit_price["FastGasPrice"]

0
import json
data = json.loads('{"status": "1", "message": "OK", "result": {"LastBlock": "14934113", "SafeGasPrice": "119", "ProposeGasPrice": "119", "FastGasPrice": "119", "suggestBaseFee": "118.174590189", "gasUsedRatio": "0.025821954106323,0.354559890356924,0.173050329701518,0.340210087647076,0.0269005272339711"}}')
SafeGasPrice = data["result"]["SafeGasPrice"]
print(SafeGasPrice)
Harun
  • 19
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 10 '22 at 01:06
  • If [it isn't JSON](https://stackoverflow.com/questions/72565438/how-to-get-string-from-json-python/72565510#comment128209110_72565438), how would this work? Did you test it? What was the result? – Peter Mortensen Jul 21 '23 at 14:41