1

我有一个包含字典的字符串:

data = 'IN.Tags.Share.handleCount({"count":17737,"fCnt":"17K","fCntPlusOne":"17K","url":"www.test.com\\/"});'

如何获取字典元素的值count?(在我的情况下是 17737)

PS也许我需要IN.Tags.Share.handleCount在通过ie获取字典之前从字符串 中删除,k = data.replace("IN.Tags.Share.handleCount", "")但是删除后仍然存在问题'()'

谢谢

4

1 回答 1

1
import re, ast
data = 'IN.Tags.Share.handleCount({"count":17737,"fCnt":"17K","fCntPlusOne":"17K","url":"www.test.com\/"});'
m = re.match('.*({.*})', data)
d = ast.literal_eval(m.group(1))
print d['count']
于 2013-01-25T09:55:34.730 回答