Json dumping a dict throws TypeError: keys must be a string

前端 未结 7 1202
余生分开走
余生分开走 2020-12-09 10:20

I am attempting to convert the following dict into JSON using json.dumps:

 {
     \'post_engaged\': 36,
     \'post_impressions\':          


        
7条回答
  •  失恋的感觉
    2020-12-09 11:04

    I know this is an old question and it already has an accepted answer, but alas the accepted answer is just totally wrong.

    The real issue here is that the code that generates the dict uses the builtin id function as key instead of the literal string "id". So the simple, obvious and only correct solution is to fix this bug at the source : check the code that generates the dict, and replace id with "id".

提交回复
热议问题