Problem analysis
Parsing a JSON string and extracting its key and value out of the list in public, first had to parse the JSON format, the following is an individual analysis process:
Source
Def read (Obj,key): collect = list () for k in obj: v = obj[k] if isinstance (V,STR) or isinstance (V,unicode): if key== ': collect.append ({k:v}) else: collect.append ({str (key) + ".") +K:V}) elif isinstance (V,int): if key== ': collect.append ({k:v}) else: collect.append ({str (key) + ".") +K:V}) elif isinstance (V,bool): if key== ': collect.append ({k:v}) else: collect.append ({str (key) + ".") +K:V}) elif isinstance (v,dict): collect.extend (Read (v,k)) elif isinstance (v,list): &nbsP; collect.extend (ReadList (v,key)) return collect def readlist (Obj,key): collect = list () for index,item in enumerate (obj): for k IN ITEM:            V = ITEM[K] if isinstance (V,STR) or isinstance (V,unicode): collect.append ({key+ "[" +STR (Index) + "]" + "." +K:V}) elif isinstance (V,int): collect.append ({key+ "[" +STR (Index) + "]" + "." +K:V}) elif isinstance (V,bool): collect.append ({key+ "[" +STR (Index) + "]" + "." +K:V}) elif isinstance (v,dict): collect.extend (Read (v,key+ "[" +STR (Index) + "]")) elif isinstance (v,list): collect.extend (ReadList (v,key+ "[" +STR (Index) + "]")) return collect
Example
Import jsonjsonstr = ' {' num ': 1, ' Boo ': true, ' obj ': {' sex ': ' Boy ', ' Age ': ' "result ': [{' Name ': ' SaaS ', ' Leverl ': [{' Name '] : "English", "Mark": "the"), "id": "336efba7-259d-4057-ae1e-679e81419cd7", "module": "Life"}]} ' OJT = Json.loads (JSONSTR) Print read (OJT, ') #输出结果 [{u ' num ': 1}, {u ' obj.age ': $}, {u ' obj.sex ': U ' Boy '}, {u ' [0].module ': U ' Life '}, {u ' [0].name ': U ' SaaS '}, {u ' [0][0].name ': U ' English '}, {u ' [0][0].mark ': ', '}, {u ' [0].id ': U ' 336efba7-259d-4057-ae1e-679e81419cd7 '}, {u ' Boo ': True}]
Python parsing JSON string