码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2017-11-14 14:20:18      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:接口   字符   使用   style   enc   ble   desc   color   des   

原文来自: 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"];

 

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

标签:接口   字符   使用   style   enc   ble   desc   color   des   

原文地址:http://www.cnblogs.com/Early-Bird/p/7831360.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!