我正在使用cakephp 3.5来创建REST API。当我使用POST MEN工具将数据发布到控制器时,我在控制器内部创建了一个控制器和方法。它给我一个意想不到的回应
以下是我在帖子数据中尝试使用的json数组
{
"type": true,
"userRole": "customer",
"signupType": "test",
"userProfile": {
"email": "admin@test.com",
"password": "YLhdh3UfH/oqppQ/P4wUBw==",
"first_name": "admin",
"last_name": "admin",
"phone_no": "admin",
"profile_image": "test.jpg",
"street_address": "test address",
"state": "Chandigarh",
"city": "Chandigarh",
"zipcode": "160022",
"latitude": "30.723306",
"longitude": "76.766114",
"rating": "5",
"role": "customer",
"status": "1"
}
}
以下是我进入方法的数据: -
Array
(
[{"type":"true","userRole":"customer","signupType":"gojus","userProfile":{"email":"admin@gojus_com","password":"YLhdh3UfH/oqppQ/P4wUBw] => =","first_name":"admin","last_name":"admin","phone_no":"admin","profile_image":"test.jpg","street_address":"test address","state":"Chandigarh","city":"Chandigarh","zipcode":"160022","latitude":"30.723306","longitude":"76.766114","rating":"5","role":"customer","status":"1"}}
)
这是我获取数据的问题“[{”我如何解决cakephp 3.5中的问题
答案 0 :(得分:1)
阅读手册:XML or JSON Data
使用REST的应用程序通常以非URL编码方式交换数据 邮政机构。您可以使用任何格式读取输入数据 HTTP \ ServerRequest ::输入()。通过提供解码功能,您可以 以反序列化格式接收内容:
// Get JSON encoded data submitted to a PUT/POST action
$jsonData = $this->request->input('json_decode');