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


Groups > comp.lang.python > #53391

Re: How do I process this using Python? (SOLVED)

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <papillion@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'string.': 0.05; 'subject:Python': 0.06; 'json': 0.07; 'string': 0.09; 'encoder': 0.09; 'guys!': 0.09; 'indicates': 0.09; 'prefix': 0.09; 'prefixes': 0.09; 'subject:process': 0.09; 'subject:using': 0.09; 'wrapped': 0.09; 'subject:How': 0.10; 'clear.': 0.16; 'incorrect': 0.16; 'parser.': 0.16; 'remembered': 0.16; 'repr()': 0.16; 'responded.': 0.16; 'shortcut': 0.16; 'simple.': 0.16; 'skip:j 30': 0.16; 'string:': 0.16; 'unicode.': 0.16; 'unicode?': 0.16; 'wrote:': 0.18; 'looked': 0.18; "python's": 0.19; 'written': 0.21; 'seems': 0.21; '>>>': 0.22; 'example': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'processor': 0.24; 'unicode': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'returned': 0.30; "i'm": 0.30; '>>>>': 0.31; 'sep': 0.31; 'text': 0.33; 'everyone': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'is.': 0.60; 'simply': 0.61; 'became': 0.64; 'needing': 0.65; 'here': 0.66; 'saw': 0.77; 'subject:this': 0.83; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=3AsSzDFtnoT4ONvyQKTU67QG7XaA3mBoSzopegIT0mA=; b=yAX2L7pB/6KgNpPubwJCbqIXO8Wh2yGnwECnv3qZiddy9G8g1NIrbw9RyEev6T6nWD AGeBYu7Rgro8N61U+Yl5pN+00Gmn9PbF70B+nBwK2QkXlNbNTChfYLMKNjFuZiJLBA7P Ht7GqG3j/2vZRRf1dwLtM+kpDDAd/9XZwxYZV9vEK1Z1cQpFRhFI5UwjCFhwU9kA20oi YO9mprRtAuDLpC8FoqI2gWQW9SIzDCTF3fPYgne90mTBUETp2D6y7cByu7cUYOb1pmDp +gfejSe+ZLDalQHiaTrt62YC88VnZvd2sbVuM9wraAT8j95XVCPCsZcPQY+1pdwgbJJ0 i/MQ==
X-Received by 10.182.242.37 with SMTP id wn5mr12048748obc.56.1377997124723; Sat, 31 Aug 2013 17:58:44 -0700 (PDT)
Date Sat, 31 Aug 2013 19:58:43 -0500
From Anthony Papillion <papillion@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8
MIME-Version 1.0
To python-list@python.org
Subject Re: How do I process this using Python? (SOLVED)
References <52227FC4.1060208@gmail.com> <CAPTjJmoHeDrUwpuiwx9+Ejz7oE7dOyYibjoTXWu4ycr7fZ2exg@mail.gmail.com> <5222881C.8060205@gmail.com> <CAPTjJmr6fZxF+4s-QDNa8C2HLwhDgEd5HeoUwekvYzyJVX+9yw@mail.gmail.com>
In-Reply-To <CAPTjJmr6fZxF+4s-QDNa8C2HLwhDgEd5HeoUwekvYzyJVX+9yw@mail.gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.435.1377997133.19984.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377997133 news.xs4all.nl 15924 [2001:888:2000:d::a6]:52402
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53391

Show key headers only | View raw


On 08/31/2013 07:32 PM, Chris Angelico wrote:
> On Sun, Sep 1, 2013 at 10:19 AM, Anthony Papillion <papillion@gmail.com> wrote:
>> On 08/31/2013 06:48 PM, Chris Angelico wrote:
>>> On Sun, Sep 1, 2013 at 9:44 AM, Anthony Papillion <papillion@gmail.com> wrote:
>>>> I'm writing a processor for Bitmessage messages and I am needing to
>>>> parse the following returned JSON string:
>>>>
>>>> {u'inboxMessages':
>>>
>>> Does the JSON string really have those u prefixes and apostrophes?
>>> That's not valid JSON. You may be able to use ast.literal_eval() on it
>>> - I was able to with the example data - but not a JSON parser. Can you
>>> sort out your transmission end?
>>>
>>> ChrisA
>>
>> I think I remembered what the 'u' prefix is. It indicates that the data
>> following is a unicode string. So could that be valid JSON data wrapped
>> up in unicode?
> 
> No; JSON already supports Unicode. What you may have is an incorrect
> JSON encoder that uses Python's repr() to shortcut its work - but it's
> wrong JSON.
> 
> But bitmessage seems to be written in Python. Can you simply access
> the objects it's giving you, rather than going via text strings?
> 
> ChrisA

Once I looked at the data in a better structured way and saw it in the
proper type it became clear. Here is my solution:

data = json.loads(api.getAllInboxMessages())
for message in data['inboxmessages']:
    print message['fromAddress']

Yep, it was that simple. Thanks for the help guys! I appreciate how fast
everyone responded.

Anthony

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


Thread

Re: How do I process this using Python? (SOLVED) Anthony Papillion <papillion@gmail.com> - 2013-08-31 19:58 -0500

csiph-web