|
|
@@ -173,6 +173,41 @@ namespace Util
|
|
|
return content;
|
|
|
}
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region 读取模版数据,替换对应的标签内容
|
|
|
+ public static string replaceKeyToValue(JsonData jsonObj, string templateString)
|
|
|
+ {
|
|
|
+ MatchCollection mc = Regex.Matches(templateString, "<<.*?>>");
|
|
|
+ foreach (Match m in mc)
|
|
|
+ {
|
|
|
+ string matchValue = m.Value;
|
|
|
+ string key = matchValue.Replace("<<", "").Replace(">>", "");
|
|
|
+ string[] keyArr = key.Split('.');
|
|
|
+ if (keyArr.Length == 1)
|
|
|
+ {
|
|
|
+ if (jsonObj[key] != null)
|
|
|
+ {
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[key].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (keyArr.Length == 2)
|
|
|
+ {
|
|
|
+ if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null)
|
|
|
+ {
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (keyArr.Length == 3)
|
|
|
+ {
|
|
|
+ if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null && jsonObj[keyArr[0]][keyArr[1]][keyArr[2]] != null)
|
|
|
+ {
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]][keyArr[2]].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return templateString;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
}
|
|
|
}
|