支持解析来自印表机的 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) |
支持解析来自印表机的 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" 的存在。