你好我想要制作json数据并发布到我的网址 这是我的新代码,但不起作用,因为我不知道如何解决它 我实际上想将这整个信息转换为json并将其发送到我请求的链接。 谢谢你的帮助
class Info
{
public $name; //String
public $_postman_id; //String
public $description; //String
public $schema; //String
}
class Header
{
public $key; //String
public $value; //String
public $description; //String
}
class Formdata
{
public $key; //String
public $value; //String
public $type; //String
public $disabled; //bool?
}
class Body
{
public $mode; //String
public $formdata; //array(Formdata)
}
class Request
{
public $url; //String
public $method; //String
public $header; //array(Header)
public $body; //Body
public $description; //String
}
class Item
{
public $name; //String
public $request; //Request
public $response; //array(Object)
}
class xibo
{
public $variables; //array(Object)
public $info; //Info
public $item; //array(Item)
}
$json_data = json_encode((array) xibo);
print_r($json_data);
$URL = "HTTP://87.98.148.67/";
$content = json_encode("mahdi");
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("ersal nashod" . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
echo $content;
答案 0 :(得分:2)
@Sushiant,你的问题得到了很多挫折,因为你的代码有很多琐碎的错误。别担心。每个人都是nubies。保持冷静和学习。
我的反馈是:
$varName = new ClassName()
创建对象。该对象是该类的一个实例。json_encode
将变量编码为json字符串。