Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53380

How do I process this using Python?

Date 2013-08-31 18:44 -0500
From Anthony Papillion <papillion@gmail.com>
Subject How do I process this using Python?
Newsgroups comp.lang.python
Message-ID <mailman.426.1377992650.19984.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How do I process this using Python? Anthony Papillion <papillion@gmail.com> - 2013-08-31 18:44 -0500
  Re: How do I process this using Python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-01 01:15 +0000

csiph-web