Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53380 > unrolled thread
| Started by | Anthony Papillion <papillion@gmail.com> |
|---|---|
| First post | 2013-08-31 18:44 -0500 |
| Last post | 2013-09-01 01:15 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | Anthony Papillion <papillion@gmail.com> |
|---|---|
| Date | 2013-08-31 18:44 -0500 |
| Subject | How do I process this using Python? |
| Message-ID | <mailman.426.1377992650.19984.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-09-01 01:15 +0000 |
| Message-ID | <52229531$0$6599$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #53380 |
On Sat, 31 Aug 2013 18:44:04 -0500, Anthony Papillion wrote: > 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. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web