支援解析來自印表機的 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) |
支援解析來自印表機的 JSON 訊息。 | |
static Dictionary< string, string > | GetKeyValuePairsFromElementList_Json (string elemName, string jsonData) |
獲取包含物件列表中鍵/值對的字典。 更多... | |
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) |
檢查訊息是否包含 "key",例如 HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}"); 更多... | |
static bool | HasKeyAtPath (string keyPath, string jsonStr) |
檢查訊息是否包含到 key 的路徑,例如 HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}"); 更多... | |
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) | |
支援解析來自印表機的 JSON 訊息。
|
static |
將 key 值作為字串返回,找不到 key 時返回空字串 (""),例如獲取 "<value1>",GetKeyAtPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");
注意 "keyPath" 可以是基於 JSON Path 表示法的點分隔路徑。 例如 "Content" 和 "Content.Item1" 是不同的路徑。第一個檢查 "Content" 的存在,第二個檢查 "Content" 中 "item1" 的存在。
|
static |
獲取包含物件列表中鍵/值對的字典。
elemName:要轉換為字典的元素,如果希望將整個字串轉換為字典,則為空字串 ("")
jsonData:JSON 字串
例如 { "item1": "value1", "item2": null, "item3": true, ... "itemN":"valueN" }
字典鍵 = JSON 鍵,例如 "item1"
字典值 = JSON 值,例如 "value1"
例如 GetKeyValueFromElementList("Content", jsonData)
其中 jsonData = { "root1": "rootVal1", "Content": { "item1": "value1", "item2": null }}
結果是包含兩個條目的字典:鍵="item1" 值="value1",鍵="item2" 值="null"
例如 GetKeyValueFromElementList("", jsonData)
其中 jsonData = { "root1": "rootVal1", "Content": "someContent"}
結果是包含兩個條目的字典:鍵="root1" 值="rootVal1",鍵="Content" 值="someContent"
|
static |
檢查訊息是否包含 "key",例如 HasKey("Content", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":...}");
注意 "key" 不會被解析為 JSON Path 表示法。 例如 "Command" 和 "Command.SubCmd.SubSubCmd" 都是有效的。
|
static |
檢查訊息是否包含到 key 的路徑,例如 HasKeyPath("Content.Item1", "{ "Command": "DoThisOrThat", "To": "SomeTgt", "From": "SomeDevice", "Content":{"item1":"<value1>",..</value1>} , ...}");
注意 "keyPath" 可以是基於 JSON Path 表示法的點分隔路徑。 例如 "Content" 和 "Content.Item1" 是不同的路徑。第一個檢查 "Content" 的存在,第二個檢查 "Content" 中 "item1" 的存在。