json-ios--URL解码成JSON

问题描述

ios--URL解码成JSON

得到响应如下:

param=%7B%22paymentMode%22:%22%22,%22transactionId%22:%2231674%22,%22pgRespCode%22:%223%22,%22TxMsg%22:%22Canceled%20by%20user%22,%22authIdCode%22:%22%22,%22currency%22:%22INR%22,%22amount%22:%221.00%22,%22addressStreet1%22:%22Sesame%20street%22,%22addressStreet2%22:%22%22,%22isCOD%22:%22%22,%22loadStatus%22:%22fail%22,%22TxId%22:%22123456%22,%22addressCountry%22:%22India%22,%22firstName%22:%22Ankur%22,%22TxGateway%22:%22%22,%22signature%22:%2245558eb93513aa7a4f2fba24e0ba577b26eb5f40%22,%22addressState%22:%22Pune%22,%22lastName%22:%22Arya%22,%22addressCity%22:%22%22,%22TxRefNo%22:%22CTX1307151506338704178%22,%22loadAmount%22:%221.00%20INR%22,%22pgTxnNo%22:%22CTX1307151506338704178%22,%22TxStatus%22:%22CANCELED%22,%22email%22:%22daredevil.suyash@gmail.com%22,%22issuerRefNo%22:%22%22,%22mobileNo%22:%229900414420%22,%22addressZip%22:%22411045%22%7D

怎么能解码成下面的呢:

param={"paymentMode":"","transactionId":"31674","pgRespCode":"3","TxMsg":"Canceled by user","authIdCode":"","currency":"INR","amount":"1.00","addressStreet1":"Sesame street","addressStreet2":"","isCOD":"","loadStatus":"fail","TxId":"123456","addressCountry":"India","firstName":"Ankur","TxGateway":"","signature":"45558eb93513aa7a4f2fba24e0ba577b26eb5f40","addressState":"Pune","lastName":"Arya","addressCity":"","TxRefNo":"CTX1307151506338704178","loadAmount":"1.00 INR","pgTxnNo":"CTX1307151506338704178","TxStatus":"CANCELED","email":"daredevil.suyash@gmail.com","issuerRefNo":"","mobileNo":"9900414420","addressZip":"411045"}

解决方案

你可以试试这个方法: stringByReplacingPercentEscapesUsingEncoding:NSStringEncodingConversionAllowLossy]

这是我从别的地方看来的。

NSString *param=@"%7B%22paymentMode%22:%22%22,%22transactionId%22:%2231674%22,%22pgRespCode%22:%223%22,%22TxMsg%22:%22Canceled%20by%20user%22,%22authIdCode%22:%22%22,%22currency%22:%22INR%22,%22amount%22:%221.00%22,%22addressStreet1%22:%22Sesame%20street%22,%22addressStreet2%22:%22%22,%22isCOD%22:%22%22,%22loadStatus%22:%22fail%22,%22TxId%22:%22123456%22,%22addressCountry%22:%22India%22,%22firstName%22:%22Ankur%22,%22TxGateway%22:%22%22,%22signature%22:%2245558eb93513aa7a4f2fba24e0ba577b26eb5f40%22,%22addressState%22:%22Pune%22,%22lastName%22:%22Arya%22,%22addressCity%22:%22%22,%22TxRefNo%22:%22CTX1307151506338704178%22,%22loadAmount%22:%221.00%20INR%22,%22pgTxnNo%22:%22CTX1307151506338704178%22,%22TxStatus%22:%22CANCELED%22,%22email%22:%22daredevil.suyash@gmail.com%22,%22issuerRefNo%22:%22%22,%22mobileNo%22:%229900414420%22,%22addressZip%22:%22411045%22%7D";
    NSString *newParam = [param stringByReplacingPercentEscapesUsingEncoding:NSStringEncodingConversionAllowLossy];
    NSLog(@"%@",newParam);
时间: 2024-10-03 05:46:09

json-ios--URL解码成JSON的相关文章

在JS中将JSON的字符串解析成JSON数据格式一般有两种方式

在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. 第一种解析方式:使用eval函数来解析,并且使用jQuery的each方法来遍历 用jQuery解析JSON数据的方法,作为jQuery异步请求的传输对象,jQuery请求后返回的结果是json对象,这里考虑的都是服务器返回JSON形式的字符串的形式,对于利用JSONObject等插件封装的JSON对象,与此亦是大同小异,这里不再做说明. 这里首先

js中把JSON字符串转换成JSON对象最好的方法

 这篇文章主要介绍了js中把JSON字符串转换为JSON对象最好的方法,需要的朋友可以参考下 在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析.   第一种解析方式:使用eval函数来解析,并且使用jQuery的each方法来遍历 用jQuery解析JSON数据的方法,作为jQuery异步请求的传输对象,jQuery请求后返回的结果是json对象,这里考虑的都是服务器返回JSON形式的字符串的形式,

JQuery把DataTable、list<>数据转换成JSON数据

   代码如下 复制代码 一般处理程序JsonDate.ashx     public void ProcessRequest(HttpContext context)     {         context.Response.ContentType = "text/plain" ;         DataTable data2 = myData();         string str = DataTableToJson( "myJson" , data2

ASP.NET 把DataTable与Lis<T>转成json输出

//DataTable转成Json public static string DataTableToJson(string jsonName, DataTable dt) { StringBuilder Json = new StringBuilder(); Json.Append("{\"" + jsonName + "\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.R

JS根据key值获取URL中的参数值及把URL的参数转换成json对象_javascript技巧

不废话了,直接贴代码了,通过示例一讲解JS根据key值获取URL中的参数值及把URL的参数转换成json对象,示例二讲解js获取url传递参数,具体内容请看下文 示例一: //把url的参数部分转化成json对象  parseQueryString: function (url) { var reg_url = /^[^\?]+\?([\w\W]+)$/, reg_para = /([^&=]+)=([\w\W]*?)(&|$|#)/g, arr_url = reg_url.exec(ur

JavaScript实现url参数转成json形式_javascript技巧

朋友问的一个面试题:有个url,要求获取url 的参数,返回值为json格式. 简单的写了下,发笔记备份. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>simple a example for url to json</title> <script> var url = 'https://www.baidu.com/s?ie=u

一个JavaScript函数把URL参数解析成Json对象_javascript技巧

问题:请编写一个JavaScript函数parseQueryString,它的用途是把URL参数解析为一个对象. eg:var obj=parseQueryString(url); 创建对象的三种形式: 一: var Person=new Object(); Person.name="Sun"; Person.age=24; 二: var Person=new Object(); Person["name"]="Sun"; Person[&quo

JavaScript将XML转成JSON的方法

 这篇文章主要介绍了JavaScript将XML转成JSON的方法,实例分析了javascript操作XML文件及格式转化的技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了JavaScript将XML转成JSON的方法.分享给大家供大家参考.具体方法如下: 1. JavaScript代码如下: 代码如下: // Changes XML to JSON function xmlToJson(xml) { // Create the return object var obj

jquery自动将form表单封装成json的具体实现

 这篇文章主要介绍了jquery自动将form表单封装成json的具体实现,需要的朋友可以参考下 前端页面:  代码如下: <span style="font-size:14px;"> <form action="" method="post" id="tf">  <table width="100%" cellspacing="0" cellpadding