python - How to read field from JSON encoding of XML message -


is there way can errormessage tag response using code in python?

{      "movies_search":{         "@xmlns":"http://www.ourmoviest.com/mv",       "@xmlns:xsi":"http://www.w3.org/2001/xmlschema-instance",       "@xsi:schemalocation":"http://www.ourmoviest.com/mv mv.xsd ",       "error":{            "errormessage":"we cannot proceed search",          "statuscode":"00004"       }    } } 

the following python script,

import json respstr = """ {      "movies_search":{         "@xmlns":"http://www.ourmoviest.com/mv",       "@xmlns:xsi":"http://www.w3.org/2001/xmlschema-instance",       "@xsi:schemalocation":"http://www.ourmoviest.com/mv mv.xsd ",       "error":{            "errormessage":"we cannot proceed search",          "statuscode":"00004"       }    } } """ respobj = json.loads(respstr) print respobj['movies_search']['error']['errormessage'] 

will print errormessage string,

we cannot proceed search 

as requested.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -