You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python中保存并重新加载Azure AnalyzeResult对象?

问题:如何将JSON加载的字典转回AnalyzeResult类实例

已执行操作:

  1. 生成文档分析结果:
with open(pdf_path, "rb") as f:
    poller = document_intelligence_client_sections.begin_analyze_document(
        "prebuilt-layout", f.read(), content_type="application/pdf", 
        output_content_format=ContentFormat.MARKDOWN, ) 
result = poller.result()

type(section_layout)
# 输出:azure.ai.documentintelligence.models._models.AnalyzeResult
  1. 将结果保存为JSON:
with open("data/section_layouts/result.json", "w") as f:
    json.dump(section_layout.as_dict(), f)
  1. 加载JSON文件:
with open("result.json", "r") as f:
    data = json.load(f)

补充信息:

使用Azure Document Intelligence SDK中的DocumentIntelligenceClient:

from azure.ai.documentintelligence import DocumentIntelligenceClient

document_intelligence_client_sections = DocumentIntelligenceClient(
    endpoint=service_endpoint, credential=default_credential)

with open(pdf_path, "rb") as f:
    poller = document_intelligence_client_sections.begin_analyze_document(
        "prebuilt-layout", f.read(), content_type="application/pdf", 
        output_content_format=ContentFormat.MARKDOWN,
)
result = poller.result()
  • 分析结果对象section_layout的类型为azure.ai.documentintelligence.models._models.AnalyzeResult
  • 该对象没有.to_dict()和.from_dict()方法

需求:

将加载JSON得到的字典格式数据,转换回AnalyzeResult类的实例格式。


内容的提问来源于stack exchange,提问作者Droid-Bird

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 07:05:04