简体   繁体   中英

PHP back-end to output a JSON response

I'm new to back end development and i'm trying to learn back end development. What i want is to create a backend using PHP which should output a json response.

For example if there's a field called First Name in my backend,and when i update that field, I want the updated name in a json response so i can display the outputs in my android app.

Sorry for being a noob.

Just point me some tutorials to learn and any further tips would be appreciated.

Outputting JSON is quite simple, you first set an HTTP Response Header and then print the JSON content. The response header is to tell the receiving application (client) what type of data to expect.

A simple example:

header('Content-Type: application/json');

echo json_encode(array(
 'name' => "Your Name"
));

You didn't mention if you were using a framework or not, but frameworks like Laravel or Lumen make this kind of thing easy.

Here's a tutorial that might be of use to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM