支持解析来自印表机的 JSON 讯息 更多...
静态 Public 成员函数 | |
static String | GetKeyValue (String key, String jsonStr) |
以字符串形式获取 key 的值,如果 key 不存在则返回空字符串 (""),例如:获取 "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}"); 更多... | |
static String | GetKeyValueAtPath (String keyPath, String jsonStr) |
以字符串形式获取 key 的值,如果 key 不存在则返回空字符串 (""),例如:获取 "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}"); 更多... | |
static Map< String, String > | GetKeyValuePairsFromElementList_Json (String elemName, String jsonData) |
获取包含对象列表中 key/value 对应的字典。 更多... | |
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) |
检查讯息是否包含“key”,例如:HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}"); 更多... | |
static boolean | HasKeyAtPath (String keyPath, String jsonStr) |
检查讯息是否包含通往“key”的路径,例如:HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}"); 更多... | |
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) | |
支持解析来自印表机的 JSON 讯息
|
static |
以字符串形式获取 key 的值,如果 key 不存在则返回空字符串 (""),例如:获取 "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");
注意:“keyPath”可能以点分隔,基于 JSON 路径标记法
例如:“Content”和“Content.Item1”为不同路径。前者检查“Content”是否存在,后者检查“Content”内的“item1”是否存在
|
static |
以字符串形式获取 key 的值,如果 key 不存在则返回空字符串 (""),例如:获取 "<value1>", GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");
注意:“keyPath”可能以点分隔,基于 JSON 路径标记法
例如:“Content”和“Content.Item1”为不同路径。前者检查“Content”是否存在,后者检查“Content”内的“item1”是否存在
|
static |
获取包含对象列表中 key/value 对应的字典。
elemName:欲转换为字典的元素名称,若为空 ("") 字符串则将整个 JSON 字符串转换为字典 jsonData:JSON 字符串
例如:{ "item1": "value1", "item2": null, "item3": true, ... "itemN":"valueN" } 字典 key = JSON key,例如 "item1" 字典 value = JSON value,例如 "value1"
例如:GetKeyValueFromElementList("Content", jsonData) 其中 jsonData = { "root1": "rootVal1", "Content": { "item1": "value1", "item2": null }} 结果为含有 2 个项目的字典:key="item1" value="value1", key="item2" value="null"
例如:GetKeyValueFromElementList("", jsonData) 其中 jsonData = { "root1": "rootVal1", "Content": "someContent"} 结果为含有 2 个项目的字典:key="root1" value="rootVal1", key="Content" value="someContent"
|
static |
检查讯息是否包含“key”,例如:HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}");
注意:“key”不会被解析为 JSON 路径标记法 例如:“Command”和“Command.SubCmd.SubSubCmd”皆为有效值
|
static |
检查讯息是否包含通往“key”的路径,例如:HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");
注意:“keyPath”可能以点分隔,基于 JSON 路径标记法
例如:“Content”和“Content.Item1”为不同路径。前者检查“Content”是否存在,后者检查“Content”内的“item1”是否存在