search

Home  >  Q&A  >  body text

python3.x - python processing javascript json

I grabbed a piece of json from the web page. When processing it in python, I encountered the problem of double quotes and single quotes. Is there anyone who has dealt with it? Can you help me?
ValueError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
Official regulations require the use of double quotes to represent characters, so I have to replace all single quotes with double quotes first?
Is there a better way?
Json.dumps() first and then loads() will not work either
Although loads() does not report an error, the processing result cannot be used as a dictionary and is in string form
TypeError: string indices must be integers

漂亮男人漂亮男人2751 days ago696

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-18 11:03:28

    There are some third-party Json libraries that can solve some compatibility issues, such as the problem of single quotes. It seems that Simplejson can do it.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-18 11:03:28

    Problem solved

    import json
    str = "[ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]"
    str = str.replace("'",'"')
    dict = json.loads(str)
    print(type(sss[0])) // dict

    reply
    0
  • Cancelreply