How to create PHP code for this JSON -
simple way create php part json code
{ "contacts": [ { "id": "c200", "name": "ravi tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, { "id": "c201", "name": "johnny depp", "email": "johnny_depp@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, ] }
i create simple json response have problem multi-objects , arrays.
you can create array like:
$a = array("contacts" => array( array( "id" => "c200", "name" => "ravi tamada", "email" => "ravi@gmail.com", "address" => "xx-xx-xxxx,x - street, x - country", "gender" => "male", "phone" => array( "mobile" => "+91 0000000000", "home" => "00 000000", "office" => "00 000000" ) ), array( "id" => "c201", "name" => "johnny depp", "email" => "johnny_depp@gmail.com", "address" => "xx-xx-xxxx,x - street, x - country", "gender" => "male", "phone" => array( "mobile" => "+91 0000000000", "home" => "00 000000", "office" => "00 000000" ) ), ) ); echo json_encode($a);
result:
{"contacts":[{"id":"c200","name":"ravi tamada","email":"ravi@gmail.com","address":"xx-xx-xxxx,x - street, x - country","gender":"male","phone":{"mobile":"+91 0000000000","home":"00 000000","office":"00 000000"}},{"id":"c201","name":"johnny depp","email":"johnny_depp@gmail.com","address":"xx-xx-xxxx,x - street, x - country","gender":"male","phone":{"mobile":"+91 0000000000","home":"00 000000","office":"00 000000"}}]}
Comments
Post a Comment