How do I get rid of the “u” from a decoded JSON object?

后端 未结 3 2267
深忆病人
深忆病人 2020-12-18 20:07

I have a dictionary of dictionaries in Python:

d = {\"a11y_firesafety.html\":{\"lang:hi\": {\"div1\": \"http://a11y.in/a11y/idea/a11y_firesafety.html:hi\"},          


        
3条回答
  •  清歌不尽
    2020-12-18 20:55

    Why do you care about the 'u' characters? They're just a visual indicator; unless you're actually using the result of str(temp) in your code, they have no effect on your code. For example:

    >>> test = u"abcd"
    >>> test == "abcd"
    True
    

    If they do matter for some reason, and you don't care about consequences like not being able to use this code in an international setting, then you could pass in a custom object_hook (see the json docs here) to produce dictionaries with string contents rather than unicode.

提交回复
热议问题