UniPRT SDK  v1.0.0.0
JsonStringTokenizer Class Reference

Support for parsing JSON msgs from printer. More...

Static Public Member Functions

static String GetKeyValue (String key, String jsonStr)
 Get key value as string, empty ("") string if key not found e.g. get "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");. More...
 
static String GetKeyValueAtPath (String keyPath, String jsonStr)
 Get key value as string, empty ("") string if key not found e.g. get "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");. More...
 
static Map< String, String > GetKeyValuePairsFromElementList_Json (String elemName, String jsonData)
 Retrieve dictionary containing key/value pairs within list of objects. More...
 
static String GetMsgId_Json (String msgStr)
 retrieve the "To" key value in the msg element. returns emptyr ("") if no "To" key present
 
static String GetMsgIdExpectedOnResponse_Json (String msgStr)
 retrieve the "From" expected for the response to the msg passed in. e.g. handles case where "From" will be empty ("") if no "From" key in msg passed in
 
static boolean HasKey (String key, String jsonStr)
 Check if msg contains "key" e.g. HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}");. More...
 
static boolean HasKeyAtPath (String keyPath, String jsonStr)
 Check if msg contains path to key e.g. HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");. More...
 
static boolean IsCmdSuccess (String msgStr)
 Check if msg is "Success" (response to a query sent to printer)
 
static boolean IsSolicitedMsg_Json (String msgStr)
 Check if msg is a solicted msg (response to a query sent to printer)
 

Detailed Description

Support for parsing JSON msgs from printer.

Member Function Documentation

◆ GetKeyValue()

static String GetKeyValue ( String  key,
String  jsonStr 
)
static

Get key value as string, empty ("") string if key not found e.g. get "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");.

Note that "keyPath" could be dot delimted based on Json Path notation
e.g. "Content" and "Content.Item1" are different paths. First one checks for existence of "Content" and second one checks for existence of "item1" within "Content"

◆ GetKeyValueAtPath()

static String GetKeyValueAtPath ( String  keyPath,
String  jsonStr 
)
static

Get key value as string, empty ("") string if key not found e.g. get "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");.

Note that "keyPath" could be dot delimted based on Json Path notation
e.g. "Content" and "Content.Item1" are different paths. First one checks for existence of "Content" and second one checks for existence of "item1" within "Content"

◆ GetKeyValuePairsFromElementList_Json()

static Map<String, String> GetKeyValuePairsFromElementList_Json ( String  elemName,
String  jsonData 
)
static

Retrieve dictionary containing key/value pairs within list of objects.


elemName: the element to convert to dictionary or empty ("") string if want entire string converted to dictionary jsonData: the JSON string

e.g. { "item1": "value1", "item2": null, "item3": true, ... "itemN":"valueN" } Dict key = JSON key, e.g. "item1" Dict value = JSON value e.g. "value1"

e.g. GetKeyValueFromElementList("Content", jsonData) where jsonData = { "root1": "rootVal1", "Content": { "item1": "value1", "item2": null }} resulst in dictionary w/ 2 entries: key="item1" value="value1", key="item2" value="null"

e.g. GetKeyValueFromElementList("", jsonData) where jsonData = { "root1": "rootVal1", "Content": "someContent"} resulst in dictionary w/ 2 entries: key="root1" value="rootVal1", key="Content" value="someContent"

◆ HasKey()

static boolean HasKey ( String  key,
String  jsonStr 
)
static

Check if msg contains "key" e.g. HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}");.

Note that "key" is NOT parsed as Json Path notation e.g. "Command" and "Command.SubCmd.SubSubCmd" are both valid

◆ HasKeyAtPath()

static boolean HasKeyAtPath ( String  keyPath,
String  jsonStr 
)
static

Check if msg contains path to key e.g. HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");.

Note that "keyPath" could be dot delimted as based on Json Path notation
e.g. "Content" and "Content.Item1" are different paths. First one checks for existence of "Content" and second one checks for existence of "item1" within "Content"