chenwolong

时间匆忙,直接上代码,回家还得做清蒸鱼呢!

  #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

@陈卧龙的博客

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2021-08-30
  • 2021-12-27
  • 2021-07-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案