Python - Parsing JSON Data Set -


i trying parse json data set looks this:

{"data":[     {     "rest":0,     "status":"the campaign moved archive",     "isactive":"no",     "statusarchive":"yes",     "login":"some_login",     "contextstrategyname":"default",     "campaignid":1111111,     "statusshow":"no",     "startdate":"2013-01-20",     "sum":0,     "statusmoderate":"yes",     "clicks":0,     "shows":0,     "managername":"xyz",     "statusactivating":"yes",     "strategyname":"highestposition",     "sumavailablefortransfer":0,     "agencyname":null,     "name":"campaign_01"     },     {     "rest":82.6200000000008,     "status":"impressions begin tomorrow @ 10:00",     "isactive":"yes",     "statusarchive":"no",     "login":"some_login",     "contextstrategyname":"default",     "campaignid":2222222,     "statusshow":"yes",     "startdate":"2013-01-28",     "sum":15998,"statusmoderate":"yes",     "clicks":7571,     "shows":5535646,     "managername":"xyz",     "statusactivating":"yes",     "strategyname":"highestposition",     "sumavailablefortransfer":0,     "agencyname":null,     "name":"campaign_02"     }     ] } 

lets assume there can many of these data sets.

i iterate through each 1 of them , grab "name" , "campaign id" parameter.

so far code looks this:

decoded_response = response.read().decode("utf-8") data = json.loads(decoded.response)      item in data[0]:         x in data[0][item] ...             -> need name procedure             -> need campaign_id procedure 

probably quite straight forward! not lists/dictionaries :(

access dictionaries d[dict_key] or d.get(dict_key, default) (to provide default value):

jsonresponse=json.loads(decoded_response) jsondata = jsonresponse["data"] item in jsondata:     name = item.get("name")     campaignid = item.get("campaignid") 

i suggest read dictionaries.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -