Reputation: 107
I have a string that contains dictionary:
data = 'IN.Tags.Share.handleCount({"count":17737,"fCnt":"17K","fCntPlusOne":"17K","url":"www.test.com\\/"});'
How can i get value of an dictionary element count
? (In my case 17737)
P.S. maybe I need to delete IN.Tags.Share.handleCount
from string before getting a dictionary by i.e.
k = data.replace("IN.Tags.Share.handleCount", "")
but the problem that '()'
remains after delete?
Thanks
Upvotes: 1
Views: 109
Reputation: 22837
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']
Upvotes: 1