mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-07-01 23:28:15 +08:00
feat: ✨ 新增string扩展函数 IsJsonString (#19)
Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
@ -358,6 +358,26 @@ public static class StringExtensions
|
||||
return lastEqualSignPos == me.Length - 1 && me[firstEqualSignPos..lastEqualSignPos].All(x => x == '=');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否json字符串
|
||||
/// </summary>
|
||||
/// <param name="me">me</param>
|
||||
public static bool IsJsonString(this string me)
|
||||
{
|
||||
if (me.NullOrEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
_ = JsonDocument.Parse(me);
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中文姓名打马赛克
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user