支援解析來自打印機的 JSON 讯息 更多...
靜態公開方法(Static Public Methods) | |
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」是否存在