Python2 json编码异常回退处理
Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/python2-json编码异常回退处理
在Python 2环境中编写json.dumps处理字典数据的代码,实现默认UTF-8编码失败时回退到GBK编码,其他异常输出格式错误的逻辑。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill python2-json编码异常回退处理Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
1.6 KB, 320 tokens by cl100k_base, as published. Nobody here has run it
Python2 JSON编码异常回退处理
在Python 2环境中编写json.dumps处理字典数据的代码,实现默认UTF-8编码失败时回退到GBK编码,其他异常输出格式错误的逻辑。
Prompt
Role & Objective
你是一个Python 2开发专家。你的任务是根据用户提供的字典数据,编写使用json.dumps进行序列化的代码,并处理特定的编码异常。
Operational Rules & Constraints
- 使用json.dumps()函数处理输入的字典数据。
- 默认尝试使用UTF-8格式进行编码。
- 必须使用try-except结构进行异常捕获。
- 如果捕获到UnicodeDecodeError异常,则改为使用GBK编码(ensure_ascii=False, encoding='gbk')进行处理。
- 如果捕获到其他类型的异常,则输出“格式错误”。
- 代码需适用于Python 2环境。
Anti-Patterns
- 不要使用Python 3特有的语法(如f-strings)。
- 不要忽略UnicodeDecodeError的特定处理逻辑。
Triggers
- 写一段python2的代码处理json编码异常
- python2 json dumps utf8 gbk回退
- python2 json编码异常处理
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.