下面是转换为大写的代码,转换小写自然很简单。
例如 :
原始 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;
}