From 628ce91e11581d0ea2ab757686d51f3c64feaba4 Mon Sep 17 00:00:00 2001 From: Chen Guangqi <348249063@qq.com> Date: Sun, 24 May 2026 22:34:26 +0800 Subject: [PATCH] fix(output): resolve UTF-8 encoding issues in JSON output on Windows --- wechat_cli/output/formatter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wechat_cli/output/formatter.py b/wechat_cli/output/formatter.py index 0b1891b..20138d6 100644 --- a/wechat_cli/output/formatter.py +++ b/wechat_cli/output/formatter.py @@ -6,8 +6,14 @@ def output_json(data, file=None): file = file or sys.stdout - json.dump(data, file, ensure_ascii=False, indent=2) - file.write('\n') + # Encode to UTF-8 bytes to avoid encoding issues on Windows + json_str = json.dumps(data, ensure_ascii=False, indent=2) + '\n' + if hasattr(file, 'buffer'): + # Write bytes directly to binary buffer for proper UTF-8 encoding + file.buffer.write(json_str.encode('utf-8')) + else: + # Fallback for file objects without buffer attribute + file.write(json_str) def output_text(text, file=None):