2

How can i convert a string like this:

"{u'value': {u'username': u'testeuser', u'status': 1,
 u'firstName': u'a', u'lastName': u'a', u'gender': u'a',
 u'date': u'2013-03-06T09:01:27.939007',
 u'id': u'b1dab21bef3f3fd050d7c2f3e8006045'},
 u'key': u'2013-03-06T09:01:27.939007'}"

to something like a list that i can find info like data['value'] or data['username'] ?

4
  • i've tried to use substr and split methods but i think its not a widespread solution. Commented Mar 27, 2013 at 15:37
  • "something like a list" you are probably looking for associative arrays Commented Mar 27, 2013 at 15:37
  • It looks a bit like a JS object literal, but those u' delimiters disturb it. How did you got that? Commented Mar 27, 2013 at 15:37
  • @Bergi It is stringifying of Python dictionary (wrong approach of serialization). Commented Mar 27, 2013 at 15:38

2 Answers 2

4

Your string looks like you've wrongly serialized your dictionary. To pass data (e.g. dictionary, list, etc) to the client side you need to serialize it in JSON format.

In order to do this in your Python code you should use json.dumps(dict) from json package, while in the client side you need to apply JSON.parse(data) to load the data back.

Sign up to request clarification or add additional context in comments.

1 Comment

with some modifications, i could send the serialized object correctly using the method you said! Thanks ;)
0
  • use eval()
  • like, I need to convert string of list-dict to list
  • by using eval("[{'range_type': '__to', 'value': '710'}, {'range_type': '__from', 'value': '700'}]") i got this: [{'range_type': '__to', 'value': '710'}, {'range_type': '__from', 'value': '700'}]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.