zoukankan      html  css  js  c++  java
  • 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"];
  • 相关阅读:
    winform中textbox属性Multiline=true时全选
    golang中的类和接口的使用
    beego上传文件
    golang 字符串操作实例
    golang操作文件
    golang获取程序运行路径
    ECharts使用心得
    es6新特性分享
    es6分享——变量的解构赋值
    NPM使用前设置和升级
  • 原文地址:https://www.cnblogs.com/Early-Bird/p/7831360.html
Copyright © 2011-2022 走看看