needed: simple way to force json to decode to "normal" iterable python lists
I've stackoverflow a ton and never found the need to ask a question
before, and while there are a lot of threads on this subject, I can't seem
to find something that is easy and makes sense. If I have somehow missed
something, please provide a link.
Here goes: I am trying to pass lists back and forth between a python
client/server using json, but am condensing the problem into a single
block to illustrate:
import json
testdata = ['word','is','bond', False, 6, 99]
# prints normal iterable list
print testdata
myjson = json.dumps(testdata)
#prints [u'word', u'is', u'bond', False, 6, 99], which contains unicode
strings
print json.loads(myjson)
# Iterates over each character, since apparently, Python does recognize it
is a list
for i in myjson:
print i
This seems wrong. I passed in an iterable list, and I got out something
that can't be used that way. I've seen a lot of answers that suggest that
I should just "deal with unicode" which is fine, if I knew how. Either I
need a way to force json to load as ascii or utf-8 or something, or a way
to allow python to iterate normally over the list containing unicode
strings normally.
Thanks!
No comments:
Post a Comment