File size: 712 Bytes
1c980b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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}")