如
{"name":"`111","password":"111","title":"111","tag":"111","contents":"1111"},{"name":"222","password":"22","title":"22","tag":"22","contents":"222"},{"name":"11","password":"11","title":"11","tag":"11","contents":"11111"}
转化为
[{"name":"`111","password":"111","title":"111","tag":"111","contents":"1111"},{"name":"222","password":"22","title":"22","tag":"22","contents":"222"},{"name":"11","password":"11","title":"11","tag":"11","contents":"11111"}]
补充一下,这是从后台传到前端的数据
雷雷
完善了一下下楼上的代码,得到了楼主想要的效果
你的意思是:
将后端传来的.json文件中的数据,放到前端新的对象数组里吧。
传的话是需要ajax的(例子是jquery的ajax方法),你也可以尝试现在比较流行的axios。
假设:
1.需要传入的文件是test.json
2.test.json的数据内容是
转换:
1.通过ajax获取到数据,获取到的内容存在了data中
2.遍历json数据并存到新的对象数组中,在success函数中进行