您的位置: 网站首页> 大家问> 当前文章

json.decoder.JSONDecodeError: Invalid control character at: line 1 column 517

老董2019-10-24154围观,141赞

  用json.loads()后报错如下:json.decoder.JSONDecodeError: Invalid control character at: line 1 column 517

  str_json = 'xxxxxxxxxxxxxxxxxxx'

  dic = json.loads(str_json)

  报错:

  son.decoder.JSONDecodeError: Invalid control character at: line 1 column 517

  原因(谷歌一把找到的):

  The problem is your unicode string contains carriage returns (\r) and newlines (\n) within a string literal in the JSON data. If they were meant to be part of the string itself, they should be escaped appropriately. If they weren't meant to be part of the string, they shouldn't be in your JSON either.

  If you can't fix where you got this JSON string to produce valid JSON, you could either remove the offending characters

  大概意思是:

  字符串含有换行\n、\r\r之类的字符,如果这些不是你需要的字符串数据,要干掉!

  然后做替换:

  str_json = str_json.replace('\n','').replace('\r\n','')

  结果还是报错

  son.decoder.JSONDecodeError: Invalid control character at: line 1 column 517

  然后加参数(百度一把找到的)

  dic = json.loads(str_json,strict=False)

  运行OK!

  注意:

  strict=False只加上这个参数不去除换行也是报错!

很赞哦!

python编程网提示:转载请注明来源www.python66.com。
有宝贵意见可添加站长微信(底部),获取技术资料请到公众号(底部)。同行交流请加群 python学习会

文章评论

    json.decoder.JSONDecodeError: Invalid control character at: line 1 column 517文章写得不错,值得赞赏

站点信息

  • 网站程序:Laravel
  • 客服微信:a772483200