[英]convert a value from json_decode to a string
我如何将我的值从json_decode转换为字符串,以便我可以传递字符串值来检查是否存在电子邮件,这是我的代码。
我的json格式如下:
{email:'test@test.com' }
PHP:
$var = json_decode($_REQUEST["email"], true);
$result = $membership->CheckEmailAddress($var); // get $var to become a string
它看起来非常丑陋,我只是启动php而我并没有走得很远。
jQuery的:
$('#checkemail').click(function () {
var json = {
email: $('#email').val()
};
$.post('http://' + location.host + '/buyme/include/getemailaddress.php', {
'email': 'test@yahoo.co.nz'
}, function (res) {
var obj = JSON.parse(res);
alert(obj.message)
});
});
也如何将我的json变量放在$ .post函数中,这就是我想放在那的值
$ _REQUEST [“ email”]中的值是上面显示的json值,然后尝试
您的$ var是一个json对象,您可以像不使用$ var那样获取电子邮件值,它是一个数组
尝试过这个:-
$val = json_encode(array('email' =>'test@test.com'));
echo $val; //output {"email":"test@test.com"}
$var = json_decode($val, true);
print_r($var); // output Array ( [email] => test@test.com )
echo $var['email']; //output test@test.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.