When we develop a Web service, we may use a JSON-based Web service protocol. If you use the Python language for development, its extensions are messages that can be processed directly in JSON format. For example, the Python JSON module introduced in Python2.6 provides the default JSON encoder and decoder, and of course you can install and use other JSON encoders/decoders.
The following code snippet is an example of parsing json in Python
Import JSON json_input = ' {"One": 1, "one": {"list": [{"Item": "A"},{"item": "B"}]} ' try: decoded = json.loads (js On_input) # Pretty printing of json-formatted string print Json.dumps (decoded, Sort_keys=true, indent=4) Print "JSON parsing example:", decoded[' one ' " print" Complex JSON parsing Example: ", decoded['-'" [' List '][1][' ite M '] except (ValueError, Keyerror, TypeError): print "JSON format error"
Here is the result of the example printing
{ "one": 1, "one": {" list": [ { "item": "A" }, { "item": "B" } ] }} JSON parsing example: 1Complex JSON parsing example: B