| import json | |
| def count_questions(json_file): | |
| with open(json_file, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| total = 0 | |
| for obj in data: | |
| # 获取question列表,若不存在则返回空列表 | |
| questions = obj.get('question', []) | |
| # 确保questions是列表类型 | |
| if not isinstance(questions, list): | |
| questions = [questions] | |
| total += len(questions) | |
| return total | |
| if __name__ == "__main__": | |
| import sys | |
| if len(sys.argv) != 2: | |
| print("Usage: python count_questions.py <json_file>") | |
| sys.exit(1) | |
| file_path = sys.argv[1] | |
| count = count_questions(file_path) | |
| print(f"Total number of questions: {count}") |