我们已经在Laravel 5和AngularJs/Ionic中运行了该Web服务来处理Web。当我们将请求从Web(客户端)发布到WebService(后端)时,我们传递了嵌套的JSON对象。在读取服务器端父对象下的所有子对象时遇到问题。
{
"name": "test",
"description": "test",
"startdate": "2016-02-21T13:00:00.000Z",
"enddate": "2016-02-23T13:00:00.000Z",
"coach": {
"uuid": "76fdd664-d830-11e5-9d46-00ffc9587cbc"
},
"category": {
"uuid": "771e6de4-d830-11e5-9d46-00ffc9587cbc"
},
"useruuid": "76d65a2d-d830-11e5-9d46-00ffc9587cbc",
"routines": ["775b2726-d830-11e5-9d46-00ffc9587cbc"]
}
这个JSON已经过验证,我也设法获得了基本的名称,例如名称,结尾等,但不是嵌套对象之一。
我们在Laravel 5中使用了类似的方法:
$incomingdata = $request->json()->all();
$name = $incomingdata->name; // works
$startdate = $incomingdata->startdate; // works
$coach_uuid = $incomingdata->coach()->uuid; // didn't work !!!
我该如何实现?
最佳答案
您可以尝试以下方法:
$phpArray = json_decode($jsonObject,true);
$name = $phpArray['name'];
$coach = $phpArray['coach'];
$coach_uuid = $phpArray['coach']['uuid'];
$category = $phpArray['category'];
$category_uuid = $phpArray['category']['uuid];