还记得在上海实习的时候,从bomb中获取数据之后,用JSON.parse来解析一下再在小程序的编辑页面中进行前端操作,现在学习后端之后终于理解原来从php后端从数据库里面读取出来的数据是二维数轴,此时如果用ajax的话无法传值,于是我用json_encode来转换成json文件再传到前端。
php后端的数据结构是:
“0” => [
["content"]=>
string(7) "1111121"
["name"]=>
string(6) "刘畅"
["type"]=>
string(6) "教师"
["update_time"]=>
int(1557390380)
["create_time"]=>
int(1557390380)
];
"1" =>[
["content"]=>
string(12) "谢谢支持"
["name"]=>
string(6) "刘畅"
["type"]=>
string(6) "教师"
["update_time"]=>
int(1557307960)
["create_time"]=>
int(1557307960)
]
经过json_ecode转换之后传到前端的数据是:
[{"reply_id":0,"message_id":1,"content":"1111121","name":"\u5218\u7545","type":"\u6559\u5e08","update_time":"2019-05-09","create_time":"2019-05-09"},
{"reply_id":0,"message_id":1,"content":"\u8c22\u8c22\u652f\u6301","name":"\u5218\u7545","type":"\u6559\u5e08","update_time":"2019-05-08","create_time":"2019-05-08"}]
注意这是个对象,就是相当于没有任何意义的字符串其中[ { " 等没有任何实质上的意义。这时候使用JSON.parse来转换之后数据结构变成:
这样就可以在前端自由的操作数据了。