want to send and receive json data in php

前端 未结 3 2021
滥情空心
滥情空心 2021-02-10 23:34

As per application requirement, I am trying to develop two PHP which can communicate with each other via Json. I tried searching online but didn\'t found solution.

Can

3条回答
  •  北海茫月
    2021-02-11 00:35

    Since you shouldn't use json_encode if the data already is in json format, change your code to something like:

    $data = array('user' => array(
             array('firstName' => 'Vignesh', 'lastName' => 'Prajapati'),
             array('firstName' => 'Vaibhav', 'lastName' => 'Prajapati')
           ));
    

    Of course you will need to add the other fields to the array as well.

    Using json_encode() on the above data will return:

    {
       "user" : [
         {
          "firstName" : "Vignesh",
          "lastName" : "Prajapati"
         },
         {
          "firstName" : "Vaibhav",
          "lastName" : "Prajapati"
         }
       ]
     }
    

提交回复
热议问题