我试图从php $ _GET获取数据然后使用rest api解析它,但它会导致错误,所以请任何人帮助..
<?php
$number=$_GET['name'];
$media=$_GET['media'];
$url = 'https://api.parse.com/1/classes/AppTo';
$appId = 'ccccc';
$restKey = 'ccccc';
$headers = array(
"Content-Type: application/json",
"X-Parse-Application-Id: " . $appId,
"X-Parse-REST-API-Key: " . $restKey
);
$objectData = '{"name":(json_encode($number)), "age":(json_encode($media))}';
$rest = curl_init();
curl_setopt($rest,CURLOPT_URL,$url);
curl_setopt($rest,CURLOPT_POST,1);
curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);
curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);
curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($rest);
echo $response;
print_r($response);
curl_close($rest);
?>
答案 0 :(得分:1)
您实际上是在发布文字{"name":(json_encode($number)), "age":(json_encode($media))}
。你可以这样构建你的json:
$objectData = json_encode(array('name' => $number, 'age' => $media));
答案 1 :(得分:1)
您发布了错误的数据更改
$objectData = '{"name":(json_encode($number)), "age":(json_encode($media))}';
到
$objectData = json_encode(array('name' => $number, 'age' => $media));