Documentation for Android

Usage Sample

The following code shows typical usage of the parser library.

import com.scandit.parser.*;
import org.json.*;
import java.util.HashMap;

...
...

Parser parser = new Parser(DataFormat.HIBC);

ParserResult res = null;
try {
    res = parser.parseString("+A99912345/$$52001510X33");
} catch (IllegalArgumentException e) {
    // Something went wrong.
}


// We can either acces the data from the raw JSON string ...
Log.d(TAG, res.getJsonString());

// ... or from the fields dictionary ...
HashMap<String, Field> map = res.getFieldsDict();
Field metaField = map.get("metadata");
Log.d(TAG, metaField.getRaw());
// parsed can be a Map<String,Object>, Object[], Integer, Long, Boolean, Double or String
Object parsed = metaField.getParsed();
Log.d(TAG, metaField.getRaw());
Log.d(TAG, parsed.toString());

// ... or from the fields array
Field[] fields = res.getFieldsArray();
for (int i = 0; i < fields.length; i++) {
    Log.d(TAG, fields[i].getName());
    Log.d(TAG, fields[i].getRaw());
    Object p = fields[i].getParsed();
    Log.d(TAG, p.toString());
}

Classes

class Parser(DataFormat format)

Defines the interface for a data string parser. To instantiate the parser, you must specify the type of the data format.

The parser type can be DataFormat.HIBC, DataFormat.GS1AI or DataFormat.DLID.

ParserResult parseString(String data_string)

Parses the data string and returns the contained fields in the result object. In case the result could not be parsed, then a java.lang.IllegalArgumentException is raised.

Returns:The parsed result
Return type:ParserResult
ParserResult parseRawData(byte[] data)

Parses the data in form of raw bytes and returns the contained fields in the result object. In case the result could not be parsed, then a java.lang.IllegalArgumentException is raised.

Returns:The parsed result
Return type:ParserResult
class ParserResult
getJsonString()
Returns:A JSON string holding the complete result. The returned string always holds an array as the top-level construct. Thus, you can convert the string into an org.json.JSONArray or use any other JSON parser of your choice. See Structure of JSON Result Object for a description of the format.
Return type:String
getFieldsDict()
Returns:A hashmap of the Field objects with key being the field name.
Return type:HashMap<String,Field>
getFieldsArray();
Returns:An array of the Field objects. Use this accessor if the order of the fields in the string matter. If you are only interested in a particular field, using the ParserResult.getFieldsDict is simpler.
Return type:Field[]
class Field
getName()
Returns:The name of the field
Return type:String
getParsed()
Returns:The parsed representation of the data contained in this field. If no parsed representation is available for the field, this property is null. Use Field.getRaw() to retrieve the data in this case.
Return type:java.lang.Object. Depending on the field, this may be an instance of Object[], HashMap<String,Object>, Integer, Long, Boolean, Double or String

This object corresponds to the JSON “parsed” field.

getRaw()
Returns:The raw substring of the original code containing the field data. For fields that are inferred and do not have a direct correspondence to a particular part of the string, the string is set to an empty string. An example of such a field is the Metadata field field of HIBC codes
Return type:String