Support for parsing JSON messages 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) |
Support for parsing JSON messages from printer. | |
static Dictionary< 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 bool | HasKey (string key, string jsonStr) |
Check if message contains "key" e.g. HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}");. More... | |
static bool | HasKeyAtPath (string keyPath, string jsonStr) |
Check if message contains path to key e.g. HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");. More... | |
static bool | IsCmdSuccess (string msgStr) |
Check if msg is "Success" (response to a query sent to printer) | |
static bool | IsSolicitedMsg_Json (string msgStr) |
Check if msg is a solicted msg (response to a query sent to printer) | |
Support for parsing JSON messages from printer.
|
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-delimited based on JSON Path notation.
e.g. "Content" and "Content.Item1" are different paths. The first one checks for existence of "Content" and the second one checks for existence of "item1" within "Content".
|
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 }}
results in dictionary with 2 entries: key="item1" value="value1", key="item2" value="null"
e.g. GetKeyValueFromElementList("", jsonData)
where jsonData = { "root1": "rootVal1", "Content": "someContent"}
results in dictionary with 2 entries: key="root1" value="rootVal1", key="Content" value="someContent"
|
static |
Check if message 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.
|
static |
Check if message 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-delimited as based on JSON Path notation.
e.g. "Content" and "Content.Item1" are different paths. The first one checks for existence of "Content" and the second one checks for existence of "item1" within "Content".