needed: simple way to force json to decode to "normal" iterable python lists -
i've stackoverflow ton , never found need ask question before, , while there lot of threads on subject, can't seem find easy , makes sense. if have somehow missed something, please provide link.
here goes: trying pass lists , forth between python client/server using json, condensing problem single block 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], contains unicode strings print json.loads(myjson) # iterates on each character, since apparently, python recognize list in myjson: print
this seems wrong. passed in iterable list, , got out can't used way. i've seen lot of answers suggest should "deal unicode" fine, if knew how. either need way force json load ascii or utf-8 or something, or way allow python iterate on list containing unicode strings normally.
thanks!
the problem you're iterating on myjson
, string, not on result of json.loads(myjson)
, iterable list.
myjson = json.dumps(testdata) mydata = json.loads(myjson) #prints [u'word', u'is', u'bond', false, 6, 99], contains unicode strings print mydata #prints ["word", "is", "bond", false, 6, 99], still string print myjson # iterates on each character, since it's string in myjson: print # iterates on list in mydata: print
Comments
Post a Comment