集成支付宝时:JSON.parse: unexpected character at line 1 column 1 of the JSON data
2017-05-05 11:42
513 查看
在集成支付宝时给IOS端返回JSON数据时遇到错误
JSON.parse: unexpected character at line 1 column 1 of the JSON data
支付宝在给请求信息进行签名:
if (str_replace('"','',$_POST['partner'])==$alipay_config['partner']&&str_replace('"','',$_POST['service'])==$alipay_config['service']) {
//将post接收到的数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串。
$data=createLinkstring($_POST);
//打印待签名字符串。工程目录下的log文件夹中的log.txt。
logResult($data);
//将待签名字符串使用私钥签名,且做urlencode. 注意:请求到支付宝只需要做一次urlencode.
$rsa_sign=urlencode(rsaSign($data, $alipay_config['private_key']));
//把签名得到的sign和签名类型sign_type拼接在待签名字符串后面。
$data = $data.'&sign='.'"'.$rsa_sign.'"'.'&sign_type='.'"'.$alipay_config['sign_type'].'"';
//返回给客户端,建议在客户端使用私钥对应的公钥做一次验签,保证不是他人传输。
echo $data;
}
else{
echo "不匹配或为空!";
logResult(createLinkstring($_POST));
}
IOS开发说要json数据,我就直接将$data 数据直接转化为json数据。支付宝处理过的字符串并不符合转化为JSON的数据要求,如果前端要求json数据不要对数据进行上面的处理。
JSON.parse: unexpected character at line 1 column 1 of the JSON data
支付宝在给请求信息进行签名:
if (str_replace('"','',$_POST['partner'])==$alipay_config['partner']&&str_replace('"','',$_POST['service'])==$alipay_config['service']) {
//将post接收到的数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串。
$data=createLinkstring($_POST);
//打印待签名字符串。工程目录下的log文件夹中的log.txt。
logResult($data);
//将待签名字符串使用私钥签名,且做urlencode. 注意:请求到支付宝只需要做一次urlencode.
$rsa_sign=urlencode(rsaSign($data, $alipay_config['private_key']));
//把签名得到的sign和签名类型sign_type拼接在待签名字符串后面。
$data = $data.'&sign='.'"'.$rsa_sign.'"'.'&sign_type='.'"'.$alipay_config['sign_type'].'"';
//返回给客户端,建议在客户端使用私钥对应的公钥做一次验签,保证不是他人传输。
echo $data;
}
else{
echo "不匹配或为空!";
logResult(createLinkstring($_POST));
}
IOS开发说要json数据,我就直接将$data 数据直接转化为json数据。支付宝处理过的字符串并不符合转化为JSON的数据要求,如果前端要求json数据不要对数据进行上面的处理。
相关文章推荐
- 集成支付宝时:JSON.parse: unexpected character at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data情况在easyui 的datagrid
- 关于SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data错误的解决
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- js - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data jquery-1.9.1.min.js:3:4315
- firefox报错 关于 JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: bad control character in string literal at line 1 column 16 of the JSON data
- SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON火狐
- json.loads(s) returns error message like this: ValueError: Invalid control character at: line 1 column 33 (char 33)
- Parse Fatal Error at line 1 column 7: The processing instruction target matching "[xX][mM][lL]" is not allowed.
- org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or
- 严重: Parse Fatal Error at line 154 column 33: Invalid byte 2 of 2-byte UTF-8 sequence.
- arse Error at line 58 column 17: The content of element type "struts-config" must match "(display-na
- Qt5:"Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document."错误
- 错误处理:com.google.gson.stream.MalformedJsonException: Unexpected value at line 1 column 15
- 错误处理:com.google.gson.stream.MalformedJsonException: Unexpected value at line 1 column 15
- 16.Checkpoint!: Adding checkpoints to the racing scenario by looking at the intersection of two line
- warning: no newline at the end of file
- warning: no newline at the end of file