用途分类 / 数据分析
Flutter Implement Json Serialization Skill 安全审计
作者说它能做什么(原文)
Create model classes with `fromJson` and `toJson` methods using `dart:convert`. Use when manually mapping JSON keys to class properties for simple data structures.
第三方安全检查结论
这次检查未发现明显风险
- 已检查文件
- 1
- 发现的风险
- 0
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。未发现风险
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。未发现风险
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。未发现风险
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险
Skill 逻辑拆解
该 Skill 的主要用途是为 Dart 模型手动生成 `fromJson` 和 `toJson`,并要求对解码结果进行显式类型检查;不匹配的字段会导致格式异常,而不是被静默接受。
查看原文
- **Import `dart:convert`**: Utilize Flutter's built-in `dart:convert` library for manual JSON encoding (`jsonEncode`) and decoding (`jsonDecode`).- **Enforce Type Safety**: Always cast the `dynamic` result of `jsonDecode()` to the expected type, typically `Map<String, dynamic>` for objects or `List<dynamic>` for arrays.- **Encapsulate Serialization Logic**: Define plain model classes containing properties corresponding to the JSON structure. Implement a `fromJson` factory constructor and a `toJson` method within the model.- **Handle Background Parsing**: If parsing large JSON documents (execution time > 16ms), offload the parsing logic to a separate isolate using Flutter's `compute()` function to prevent UI jank. // Factory constructor for deserialization factory User.fromJson(Map<String, dynamic> json) { return switch (json) { { 'id': int id, 'name': String name, 'email': String email, } => User( id: id, name: name, email: email, ), _ => throw const FormatException('Failed to load User.'), };网络访问属于条件式工作流:它建议使用 `http` 包发起请求、检查响应状态并解析响应。所提供的请求仅是指向 `api.example.com` 的示例,没有出现真实服务地址、凭据、上传逻辑或隐蔽数据传输。
查看原文
## Workflow: Fetching and Parsing JSONUse this conditional workflow when retrieving and parsing JSON from a network request.1. **Execute Request**: Use the `http` package to perform the network call.2. **Validate Response**: - If `response.statusCode == 200` (or 201 for POST), proceed to parsing. - If the status code indicates failure, throw an `Exception`.3. **Determine Parsing Strategy**: - If parsing a **small payload** (e.g., a single object), parse synchronously on the main thread. - If parsing a **large payload** (e.g., an array of thousands of objects), use `compute(parseFunction, response.body)` to parse in a background isolate.4. **Decode and Map**: Pass the decoded JSON to your model's `fromJson` constructor.Future<User> fetchUser(http.Client client, int userId) async { final response = await client.get( Uri.parse('https://api.example.com/users/$userId'), headers: {'Accept': 'application/json'}, );对于大型响应,该 Skill 建议把 JSON 解码和模型映射放到 Flutter 后台 isolate,以减少主线程卡顿;示例只处理传入的响应字符串。
查看原文
- **Encapsulate Serialization Logic**: Define plain model classes containing properties corresponding to the JSON structure. Implement a `fromJson` factory constructor and a `toJson` method within the model.- **Handle Background Parsing**: If parsing large JSON documents (execution time > 16ms), offload the parsing logic to a separate isolate using Flutter's `compute()` function to prevent UI jank.- **Throw Exceptions on Failure**: When handling HTTP responses, throw an exception if the status code is not successful (e.g., not 200 OK or 201 Created). Do not return `null`.// Top-level function required for compute()List<User> parseUsers(String responseBody) { final parsed = (jsonDecode(responseBody) as List<dynamic>).cast<Map<String, dynamic>>(); return parsed.map<User>((json) => User.fromJson(json)).toList();}Future<List<User>> fetchUsers(http.Client client) async { final response = await client.get( Uri.parse('https://api.example.com/users'), headers: {'Accept': 'application/json'}, ); if (response.statusCode == 200) { // Offload expensive parsing to a background isolate return compute(parseUsers, response.body); } else {从这里开始 · 工作说明SKILL.md
flutter-implement-json-serialization文件与检查记录1 个文件
检查范围与遗漏
逐文件查看涉及的内容
下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。
SKILL.md已纳入全文
这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。
SKILL.md工作说明
代码和说明中提到的操作
连接外部网站
final response = await client.get( Uri.parse('https://api.example.com/users/$userId'), headers: {'Accept': 'application/json'}, final response = await client.get( Uri.parse('https://api.example.com/users'), headers: {'Accept': 'application/json'},- 读取了多少行
- 154
- 文件校验值(用于核对版本)
- 4c9bafec450674912c52cbaa5ba894d8427364f266cba9871ff4916bf73d1a4b