下面是转换为大写的代码,转换小写自然很简单。
例如 :
原始 str = {“cmd”:"Move"}
转换结果 str = {“CMD”:"Move"}
public static string JsonKeyToUpper(string strJson)
{
MatchCollection ms = Regex.Matches(strJson, "\\\"[a-zA-Z0-9]+\\\"\\s*:");
foreach (Match item in ms)
{
string s1 = item.Value;
string s2 = item.Value.ToUpper();
//strJson.Replace()
strJson = strJson.Replace(s1, s2);
}
return strJson;
}
本文介绍了一种将JSON字符串中所有键名转换为大写的方法。通过使用C#中的正则表达式和字符串替换功能,可以实现键名大小写的统一转换。
3392

被折叠的 条评论
为什么被折叠?



