您好,欢迎访问一九零五行业门户网

PHP中json文件上传的方法介绍(代码示例)

本篇文章给大家带来的内容是关于php中json文件上传的方法介绍(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
http:一种超文本的传输协议,是计算机与计算机沟通的一种标准协议,现在一般为端与端之间的通信。
1、约定内容
请求/响应报文格式
请求方法 get/post
响应状态 200/404/302/304
预设的请求/响应头
php中的header函数用于设置响应头
585ab92f119e99acc23d39e1b4ecb0ac
补充:
7a14aad88ae0761a10b3fe9012dcee87
客户端浏览器在接受到这个头信息后自动跳转到指定地址
json
json:类似于js字面量的表达数据的手段
json中属性名称必须用双引号
json中字符串必须用双引号(js的字符串可以用单引号)
json不允许注释
json数据类型
null:
 null
string:
ssq
boolean:
turenumber:
 12
object:
 {    name: ssq,    age: 12,    gender: ture,    boyfrind: null}
array:
 [张三, 李四, 王五]
json基本格式
var obj = [    {name: ss, age: 12, email: ssss, url: sssss.com, images: [./images/01.jpg]},    {name: ss, age: 12, email: ssss, url: sssss.com, images: [./images/01.jpg]},    {name: ss, age: 12, email: ssss, url: sssss.com, images: [./images/01.jpg]},    {name: ss, age: 12, email: ssss, url: sssss.com, images: [./images/01.jpg]},    {name: ss, age: 12, email: ssss, url: sssss.com, images: [./images/01.jpg]}]
json的转换
在php中对json反序列化
<?php$contents = file_get_contents('storage.json');$data = json_decode($contents, true);?>
及变成php中对象数组的形式
01实例展示
<?php// 获取文件中记录的数据,并展示到表格中(动态生成表格的html标签)$contents = file_get_contents('storage.json');// $contents => json 格式的字符串// 把 json 格式的字符串转换为对象的过程叫做反序列化// json_decode 默认反序列化时 将 json 中的对象转换为 php 中 stdclass 类型的对象$data = json_decode($contents, true);// $data => []?><!doctype html><html><head> <meta charset="utf-8"> <title>音乐列表</title> <link rel="stylesheet" href="bootstrap.css"></head><body> <div class="container py-5"> <h1>音乐列表</h1> <hr> <div> <a href="add.php" class="btn btn-secondary btn-sm">添加</a> </div> <table class="table table-bordered table-striped table-hover"> <thead> <tr> <th>标题</th> <th>歌手</th> <th>海报</th> <th>音乐</th> <th>操作</th> </tr> </thead> <tbody> <?php foreach ($data as $item): ?> <tr> <td><?php echo $item['title'] ?></td> <td><?php echo $item['artist'] ?></td> <td><img src="<?php echo $item['images[0]'] ?>" alt=""></td> <td><audio src="<?php echo $item['source'] ?>" controls></audio></td> <td><button class="btn btn-danger btn-sm">删除</button></td> </tr> <?php endforeach ?> </tbody> </table> </div></body></html>
效果图
以上就是php中json文件上传的方法介绍(代码示例)的详细内容。
其它类似信息

推荐信息