使用python将json中的字符串组合为单个字符串

时间:2014-08-15 19:03:51

标签: python json

我有一个json如下:

{'body_text': [u'The',u'in Wynnewood, OK, just south of Oklahoma City,\xa0is h',u'eral different exotic animals:']}

如何获得输出:

{'body_text': [u'The in Wynnewood, OK, just south of Oklahoma City,\xa0is heral different exotic animals:']}

1 个答案:

答案 0 :(得分:1)

您可以使用str.join。这允许连接字符串列表,在其间插入另一个字符串:

d = {'body_text': [u'The',u'in Wynnewood, OK, just south of Oklahoma City,\xa0is h',u'eral different exotic animals:']}

d['body_text'] = ' '.join(d['body_text'])
print d

输出

{'body_text': 'The in Wynnewood, OK, just south of Oklahoma City,\xa0is h eral different exotic animals:'}