• C#解析"a=1&b=2&c=3"字符串,微信支付返回字符串,替换<br>为&


    原文来自: http://www.mzwu.com/article.asp?id=2802

    C#可用:

    若该字符串是使用Http Get发送,url?a=1&b=2&c=3,使用下边代码即可获取参数a的值:

    程序代码
    Request.QueryString["a"]


    若该字符串是远程接口返回,以前都是用Split函数去拆分,今天发现一个非常强大的方法ParseQueryString,简单多了:

     程序代码
    <%@ WebHandler Language="C#" class="Default" %>
    
    using System;
    using System.Web;
    using System.Text;
    using System.Collections.Specialized;
    
    public class Default : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
    
            string str = "a=1&b=2&c=3";
            NameValueCollection query = HttpUtility.ParseQueryString(str, Encoding.GetEncoding("gb2312"));
            context.Response.Write(query["a"]);
        }
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }

    C#例子代码:

                resultDescription = resultDescription.Replace("<br>", "&");
                NameValueCollection query = HttpUtility.ParseQueryString(resultDescription, Encoding.GetEncoding("gb2312"));
                responseModel.MicroPayRequestModel = new Models.RequestModel.MicroPayRequestModel();
                responseModel.MicroPayRequestModel.Appid = query["appid"];
    responseModel.MicroPayRequestModel.XXX= query["XXX"];
  • 相关阅读:
    VB6 获取和设置默认打印机
    VB操作EXCEL文件大全
    VB常用字符串操作函数
    VB数组的清除
    清理系统内存
    转:清理系统垃圾的BAT代码
    对Kalman(卡尔曼)滤波器的理解
    Kernel Memory Layout on ARM Linux
    linux kernel内存映射实例分析
    基于ARM的模拟器
  • 原文地址:https://www.cnblogs.com/Early-Bird/p/7831360.html
Copyright © 2020-2023  润新知