Skip to content

Commit fdc5086

Browse files
committed
Update 2.read-a-drivers-license.html
1 parent d7849f6 commit fdc5086

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

4.use-case/2.read-a-drivers-license.html

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,32 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
193193
let parser = await (pParser = pParser || Dynamsoft.DCP.CodeParser.createInstance());
194194

195195
let parsedDLInfo = await parser.parse(bytesToParse);
196+
if (parsedDLInfo.exception) return;
196197
parsedDLInfo = JSON.parse(parsedDLInfo.jsonString);
198+
console.log(parsedDLInfo);
197199
let resultShowNode = document.createElement("p");
198200
oriParseInfo = {};
199-
for (let info of parsedDLInfo.ResultInfo) {
200-
oriParseInfo[info.FieldName] = info.Value;
201-
if (info.ChildFields) {
202-
wrapResultObject(info.ChildFields);
201+
if (parsedDLInfo.CodeType === "AAMVA_DL_ID") {
202+
for (let info of parsedDLInfo.ResultInfo) {
203+
if (info.FieldName !== "commonSubfile") continue;
204+
if (info.ChildFields) {
205+
wrapResultObject(info.ChildFields);
206+
}
207+
}
208+
} else if (parsedDLInfo.CodeType === "AAMVA_DL_ID_WITH_MAG_STRIPE") {
209+
for (let info of parsedDLInfo.ResultInfo) {
210+
if (info.FieldName.includes("track")) {
211+
if (info.ChildFields) {
212+
wrapResultObject(info.ChildFields);
213+
}
214+
}
215+
}
216+
} else if (parsedDLInfo.CodeType === "SOUTH_AFRICA_DL") {
217+
for (let info of parsedDLInfo.ResultInfo) {
218+
oriParseInfo[info.FieldName] = info.Value;
219+
if (info.ChildFields) {
220+
wrapResultObject(info.ChildFields);
221+
}
203222
}
204223
}
205224
for (let o in oriParseInfo) {
@@ -224,8 +243,9 @@ <h1 id='header'>Read A Driver's License <a href="javascript:void(0)" id='readAga
224243
function wrapResultObject(childFields) {
225244
for (let childField of childFields) {
226245
for (let field of childField) {
227-
if (["dataElementSeparator", "segmentTerminator"].includes(field.FieldName)) continue;
228-
oriParseInfo[field.FieldName] = field.Value;
246+
if (!["dataElementSeparator", "segmentTerminator", "subfile", "subfileType"].includes(field.FieldName)) {
247+
oriParseInfo[field.FieldName] = field.Value;
248+
}
229249
if (field.ChildFields) {
230250
wrapResultObject(field.ChildFields);
231251
}

0 commit comments

Comments
 (0)