我试图以json格式获得正确的输出,但是我的输出下面有点乱。它应该是这样的: "{"table":"users","operation":"select","username":"inan"}"
阵列打印为json,数组和xml
我该如何解决我的问题?
由于
server.php
print_r($_POST);
client.php
$data = array('table'=>'users', 'operation'=>'select', 'uid'=>'yoyo');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($curl_handle);
if ($this->request_response_type == 'array')
{
echo $output;
}
else if ($this->request_response_type == 'json')
{
echo json_encode($output);
}
else if ($this->request_response_type == 'xml')
{
//xml conversion will be done here later. not ready yet.
}
输出:
"Array\n(\n [table] => users\n [operation] => select\n [uid] => yoyo\n)\n"
你显示的输出是一个php数组的print_r。如果你想要json,请仔细检查'$ this-> request_response_type'是否返回'json',并记住它是区分大小写的,所以'Json'!='json'。 – 2013-02-15 18:05:57