時間匆忙,直接上代碼,回家還得做清蒸魚呢!
#region 獲取Json字符串某節點的值 /// <summary> /// 獲取Json字符串某節點的值 /// </summary> public static string GetJsonValue(string jsonStr, string key) { string result = string.Empty; if (!string.IsNullOrEmpty(jsonStr)) { key = "\"" + key.Trim('"') + "\""; int index = jsonStr.IndexOf(key) + key.Length + 1; if (index > key.Length + 1) { //先截逗號,若是最后一個,截“}”號,取最小值 int end = jsonStr.IndexOf(',', index); if (end == -1) { end = jsonStr.IndexOf('}', index); } result = jsonStr.Substring(index, end - index); result = result.Trim(new char[] { '"', ' ', '\'' }); //過濾引號或空格 } } return result; } #endregion
獲取XML某節點的值、
#region XML KEY /// <summary> /// XML KEY 通用方法 /// </summary> /// <returns></returns> public static string GetXMLstrByKey(string Key, XmlDocument xml) { object strValue = xml.SelectSingleNode("xml").SelectSingleNode(Key).InnerText; if (strValue != null) { return strValue.ToString(); } else { return ""; } } #endregion
@陳卧龍的博客