How do I process this using Python?

  • Thread starter Anthony Papillion
  • Start date
A

Anthony Papillion

Hello Everyone,

I'm writing a processor for Bitmessage messages and I am needing to
parse the following returned JSON string:

{u'inboxMessages': [{u'fromAddress':
u'BM-2DBYkhiBZCyrBa8J7gFRGrFRSGqtHgPtMvwQ', u'toAddress':
u'BM-2DC7SCTj2gzgrGgMvUCARdrfrsgLyz3iMyN3', u'read': 0, u'msgid':
u'36659a4453e12a085d8fbfeefc58da8fb23f38bfb0984c2983e0ddc31c776038',
u'receivedTime': u'1377986524', u'message':
u'dGVzdGluZyAxIDIgMw0KDQotLQ0KSm9obiBQZXJyeQ0KDQo=\n', u'encodingType':
2, u'subject': u'bWVzc2FnZSAx\n'}, {u'fromAddress':
u'BM-2DBYkhiBZCyrBa8J7gNBrngtgttHgPtMvwQ', u'toAddress':
u'BM-2DC7SCTj2gzgrGgMvUCARdCrfthyz3iMyN3', u'read': 0, u'msgid':
u'2ebe10c788ed47c6c122e3b43ae6642cb15077536c7056ed5088ab2d339c4630',
u'receivedTime': u'1377986557', u'message':
u'VGhpcyBpcyB0aGUgbmV4dCB0ZXN0DQoNCi0tDQpKb2huIFBlcnJ5DQoNCg==\n',
u'encodingType': 2, u'subject': u'dGVzdGluZyAzIDQgNQ==\n'},
{u'fromAddress': u'BM-2DBYkhithgyhyrBa8J7gNBrnSGqtHgPtMvwQ',
u'toAddress': u'BM-2DC7SCTj2gzgrtgtgMvUCARdCogLyz3iMyN3', u'read': 0,
u'msgid':
u'91dffd421c898aab0ffc43a363869a580abec6fa851aa6cf7cefe98263f96c81',
u'receivedTime': u'1377986599', u'message':
u'VGhpcyBpcyB0aGUgM3JkIHRlc3QNCg0hjj0NCkpvaG4gUGVycnkNCg0K\n',
u'encodingType': 2, u'subject': u'dGhpcyBpcyB0aGUgM3Jk\n'}]}

I tried using the following code:

data = json.loads(api.getAllInboxMessages) # This is the API call

for messageSender in data['inboxMessages']['fromAddress']
print messageSender

For some reason (probably obvious reasons) isn't working. I'm trying to
loop through the JSON and return all of the fromAddress fields.

Can anyone offer suggestions?

Thanks,
Anthony
 
S

Steven D'Aprano

Hello Everyone,

I'm writing a processor for Bitmessage messages and I am needing to
parse the following returned JSON string: [...]
For some reason (probably obvious reasons) isn't working. I'm trying to
loop through the JSON and return all of the fromAddress fields.

Can anyone offer suggestions?


Yes. Don't assume that "isn't working" is obvious. What do you mean
"isn't working"? What part isn't working? What does it do? Does it print
the wrong results, or does it raise an exception? If so, please copy and
paste the entire traceback, do not simplify it, summarise it, or retype
it from memory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top