我将收到一个JSON编码的字符串形式Obj-C,我正在解码一个虚拟字符串(现在),如下面的代码.我的输出带有每个项目前缀字符'u':
[{u'i': u'imap.gmail.com', u'p': u'aaaa'}, {u'i': u'333imap.com', u'p': u'bbbb'}...
Run Code Online (Sandbox Code Playgroud)
JSON如何添加这个unicode char?删除它的最佳方法是什么?
mail_accounts = []
da = {}
try:
s = '[{"i":"imap.gmail.com","p":"aaaa"},{"i":"imap.aol.com","p":"bbbb"},{"i":"333imap.com","p":"ccccc"},{"i":"444ap.gmail.com","p":"ddddd"},{"i":"555imap.gmail.com","p":"eee"}]'
jdata = json.loads(s)
for d in jdata:
for key, value in d.iteritems():
if key not in da:
da[key] = value
else:
da = {}
da[key] = value
mail_accounts.append(da)
except Exception, err:
sys.stderr.write('Exception Error: %s' % str(err))
print mail_accounts
Run Code Online (Sandbox Code Playgroud) 我在Python中有一本字典词典:
d = {"a11y_firesafety.html":{"lang:hi": {"div1": "http://a11y.in/a11y/idea/a11y_firesafety.html:hi"}, "lang:kn": {"div1": "http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn}}}
Run Code Online (Sandbox Code Playgroud)
我在JSON文件中有这个,我用它编码json.dumps().现在,当我使用json.loads()Python 解码它时,我得到一个这样的结果:
temp = {u'a11y_firesafety.html': {u'lang:hi': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:hi'}, u'lang:kn': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn'}}}
Run Code Online (Sandbox Code Playgroud)
我的问题在于"u",它表示我的temp(字典词典)中每个项目前面的Unicode编码.如何摆脱那个"你"?