Parsing JSON Data in Python
In Python, parsing JSON data involves using the json module. If you have JSON data in a string, you can use the json.loads method to convert it into a Python dictionary:
import json json_str = '{ "one": "1", "two": "2", "three": "3" }' data = json.loads(json_str)
Once you have the JSON data as a dictionary, you can access individual values using the key names as shown below:
result = data['two'] print(result) # Output: 2
Example:
In the example provided, we have a JSON string jsonStr and an input string key as "two". To retrieve the corresponding value, you can use the following code:
import json json_str = '{ "one": "1", "two": "2", "three": "3" }' key = "two" data = json.loads(json_str) result = data[key] print(result) # Output: 2
The above is the detailed content of How to Parse JSON Data in Python Using the `json` Module?. For more information, please follow other related articles on the PHP Chinese website!