Laravel从json制作数组

时间:2016-03-04 12:25:20

标签: php json laravel-5.2

我已经制作了api,现在我想在我的webapp中使用该api。当我在postman中检查api的输出时,结果只是json:

邮递员的结果:

"{"result":{"message":"Success","school":[{"SchoolName":"Lehner-Hackett","Company":"Dare, Bailey and Bednar","Address":"33972 Mills LockDuBuqueshire, FL 74380","Zip":"52192-","City":"Kubshirecvd","PhoneNumber":"572-489-9606435"},{"SchoolName":"O'Conner PLC","Company":"Dare, Bailey and Bednar","Address":"46849 Tara Plaza\nNew Berenicemouth, NV 36571","Zip":"24669","City":"North Francesview","PhoneNumber":"1-373-907-1357"},{"SchoolName":"Botsford-Huels","Company":"Dare, Bailey and Bednar","Address":"668 Georgiana Lights\nPort Payton, PA 90419-1623","Zip":"56373","City":"Nashville","PhoneNumber":"1-255-355-1138"}]}}"

在我的api中,我像这样返回json:

return  $output = [
                    'SchoolName'    => $school->SchoolName,
                    'Company'       => $school->company->CompanyName,
                    'Address'       => $school->Address,
                    'Zip'           => $school->Zip,
                    'City'          => $school->City,
                    'PhoneNumber'   => $school->PhoneNumber
                ];

如果我在webapp中得到结果,结果就是:

JsonResponse {#247 ▼
  #jsonOptions: 0
  #data: "{"school":[[{"SchoolName":"Lehner-Hackett","Company":"Dare, Bailey and Bednar","Address":"33972 Mills LockDuBuqueshire, FL 74380","Zip":"52192-","City":"Kubshirecvd","PhoneNumber":"572-489-9606435"},{"SchoolName":"O'Conner PLC","Company":"Dare, Bailey and Bednar","Address":"46849 Tara Plaza\nNew Berenicemouth, NV 36571","Zip":"24669","City":"North Francesview","PhoneNumber":"1-373-907-1357"},{"SchoolName":"Botsford-Huels","Company":"Dare, Bailey and Bednar","Address":"668 Georgiana Lights\nPort Payton, PA 90419-1623","Zip":"56373","City":"Nashville","PhoneNumber":"1-255-355-1138"}]]}"
  #callback: null
  #encodingOptions: 15
  +headers: ResponseHeaderBag {#245 ▶}
  #content: "{"school":[[{"SchoolName":"Lehner-Hackett","Company":"Dare, Bailey and Bednar","Address":"33972 Mills LockDuBuqueshire, FL 74380","Zip":"52192-","City":"Kubshirecvd","PhoneNumber":"572-489-9606435"},{"SchoolName":"O'Conner PLC","Company":"Dare, Bailey and Bednar","Address":"46849 Tara Plaza\nNew Berenicemouth, NV 36571","Zip":"24669","City":"North Francesview","PhoneNumber":"1-373-907-1357"},{"SchoolName":"Botsford-Huels","Company":"Dare, Bailey and Bednar","Address":"668 Georgiana Lights\nPort Payton, PA 90419-1623","Zip":"56373","City":"Nashville","PhoneNumber":"1-255-355-1138"}]]}"
  #version: "1.0"
  #statusCode: 200
  #statusText: "OK"
  #charset: null
}

为什么我的网络应用程序会收到其他内容?

0 个答案:

没有答案