JSON我通过Ajax发送查询字符串格式化的文本像波纹管PHP脚本:转换查询字符串在PHP
title=hello&custLength=200&custWidth=300
而且我想这个文本JSON对象通过这个结果在PHP转换:
{
"title" : "hello",
"custLength" : 200,
"custWidth" : 300
}
我怎样才能做到这一点。有没有人有办法解决吗?
编辑: 事实上,我必须以形成三个元件由标题,custLength和custWidth名称和我试图经由的serialize() jquery的方法来发送这些元素作为一个参数到PHP脚本。
这个代码是用于发送数据到PHP:
customizingOptions = $('#title,#custLength,#custWidth').serialize();
$.post('cardOperations',{action:'add','p_id':p_id,'quantity':quantity,'customizingOptions':customizingOptions},function(data){
if (data.success){
goBackBtn('show');
updateTopCard('new');
}
},'json');
在PHP脚本我用json_encode()的转换只customizingOptions参数为JSON。
但结果不是我所期望的和结果是一个简单的文字是这样的:
"title=hello&custLength=200&custWidth=300"
哪一部分是它是你坚持?读取查询字符串或写入JSON? – JJJ
echo json_encode($ _ GET);试试这个 – Codelord
我已经添加了更多的细节问题。 –