简体   繁体   中英

deserialize RecognizedForm object from json (Azure Form Recognizer Python SDK)

I need to deserialize json-serialized Azure Form Recognizer results into python FormRecognizer objects (from azure-ai-formrecognizer==3.1.0b1 package), and I do not see any sort of api to perform this deserialization. Any help would be appreciated.

Depending on how you are parsing, if you just need to access RecognizedForm attributes and don't need a true RecognizedForm object (in other words, just the shape of a RecognizedForm object), this might work for you:

import json
from types import SimpleNamespace
recognized_form = json.loads(recognized_form_json, object_hook=lambda fields: SimpleNamespace(**fields))

Otherwise, we can manually deserialize it back to a RecognizedForm . See this gist for an example (not fully tested).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM