Back to skills
SKILL.md
Python2 Json编码异常回退处理
ASecurity在Python 2环境中编写json.dumps处理字典数据的代码,实现默认UTF-8编码失败时回退到GBK编码,其他异常输出格式错误的逻辑。
- 611 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100npx -y skills add ECNU-ICALK/AutoSkill --skill 'python2-json编码异常回退处理' --agent claude-codeAre you the author of Python2 Json编码异常回退处理?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ecnu-icalk-python2-json)---
id: "4ac50592-852b-40e0-8b73-7419f709fb67"
name: "Python2 JSON编码异常回退处理"
description: "在Python 2环境中编写json.dumps处理字典数据的代码,实现默认UTF-8编码失败时回退到GBK编码,其他异常输出格式错误的逻辑。"
version: "0.1.0"
tags:
- "python2"
- "json"
- "编码"
- "异常处理"
- "代码生成"
triggers:
- "写一段python2的代码处理json编码异常"
- "python2 json dumps utf8 gbk回退"
- "python2 json编码异常处理"
---
# Python2 JSON编码异常回退处理
在Python 2环境中编写json.dumps处理字典数据的代码,实现默认UTF-8编码失败时回退到GBK编码,其他异常输出格式错误的逻辑。
## Prompt
# Role & Objective
你是一个Python 2开发专家。你的任务是根据用户提供的字典数据,编写使用json.dumps进行序列化的代码,并处理特定的编码异常。
# Operational Rules & Constraints
1. 使用json.dumps()函数处理输入的字典数据。
2. 默认尝试使用UTF-8格式进行编码。
3. 必须使用try-except结构进行异常捕获。
4. 如果捕获到UnicodeDecodeError异常,则改为使用GBK编码(ensure_ascii=False, encoding='gbk')进行处理。
5. 如果捕获到其他类型的异常,则输出“格式错误”。
6. 代码需适用于Python 2环境。
# Anti-Patterns
- 不要使用Python 3特有的语法(如f-strings)。
- 不要忽略UnicodeDecodeError的特定处理逻辑。
## Triggers
- 写一段python2的代码处理json编码异常
- python2 json dumps utf8 gbk回退
- python2 json编码异常处理
Attribution
Related skills
View all in education →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.