import json print("Loading peiwenyunfu.json...") with open('peiwenyunfu.json', 'r', encoding='utf-8') as f: data = json.load(f) current_vol = "" fixed_count = 0 for rhyme, r_data in data.items(): if rhyme in ['metadata', 'preface']: continue vol = r_data.get("卷", "") if vol.strip(): # Update current valid volume current_vol = vol.strip() else: # If volume is empty, use the current_vol if current_vol: r_data["卷"] = current_vol fixed_count += 1 print(f"Fixed {fixed_count} missing volumes.") with open('peiwenyunfu.json', 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4) print("Saved to peiwenyunfu.json!")