简体   繁体   English

如何从 wordpress 上的 .json 文件中提取信息

[英]How to pull information from a .json file on wordpress

I have a website with a contact form.我有一个带有联系表格的网站

The form has a field called POS Company Name ". I need to populate this field with items that I need to pull from a .json file.该表单有一个名为“ POS Company Name ”的字段。我需要使用我需要从.json文件中提取的项目填充此字段。

 [ { "name": "POSitouch", "supportedVersions": [ "5.36+", "6.36+", "QuickMenu 2.6.7.12+" ] }, { "name": "Aloha", "supportedVersions": [ "5.1+" ] }, { "name": "Posera Maitre'D", "supportedVersions": [ "7.0" ] }, { "name": "Veloce", "supportedVersions": [ "6.x", "7.x", "8.x", "9.x" ] }, { "name": "Azbar AZPos", "supportedVersions": [ "6.x", "7.x", "8.x" ] }, { "name": "Dinerware", "supportedVersions": [ "3.x" ] }, { "name": "Micros 3700", "supportedVersions": [ "RES4", "RES5" ] }, { "name": "Micros Simphony", "supportedVersions": [ "1.6+" ] }, { "name": "Micros First Edition", "supportedVersions": [ "1.6+" ] }, { "name": "EPOS Now", "supportedVersions": [ "All Versions" ] }, { "name": "Maxirest", "supportedVersions": [ "4.9+" ] }, { "name": "Silverware", "supportedVersions": [ "Avrio", "Legacy" ] }, { "name": "OKPOS", "supportedVersions": [ "All Versions" ] }, { "name": "Tiller", "supportedVersions": [ "All Versions" ] }, { "name": "Tango", "supportedVersions": [ "All Versions" ] }, { "name": "Zonal", "supportedVersions": [ "Aztec 3.6+" ] }, { "name": "Lavu", "supportedVersions": [ "All Versions" ] }, { "name": "Bepoz/Vectron", "supportedVersions": [ "4.3+" ] }, { "name": "EasyPos", "supportedVersions": [ "All Versions" ] }, { "name": "IdealPos", "supportedVersions": [ "7.x+" ] }, { "name": "H&L", "supportedVersions": [ "8+" ] } ]

When a user clicks this field, it needs to show the list of items that are displayed in the .json file.当用户单击此字段时,它需要显示.json file.中显示的项目列表.json file. The website can pull this data and store it locally in file or db, or call it on every request.网站可以提取这些数据并将其存储在本地文件或数据库中,或者在每个请求时调用它。

You can user a function with for loop to insert in wordpress html.您可以使用带有 for 循环的函数插入 wordpress html。

 window.onload = function load (){ console.log ('readyu'); var json = [ { "name": "POSitouch", "supportedVersions": [ "5.36+", "6.36+", "QuickMenu 2.6.7.12+" ] }, { "name": "Aloha", "supportedVersions": [ "5.1+" ] }, { "name": "Posera Maitre'D", "supportedVersions": [ "7.0" ] }, { "name": "Veloce", "supportedVersions": [ "6.x", "7.x", "8.x", "9.x" ] }, { "name": "Azbar AZPos", "supportedVersions": [ "6.x", "7.x", "8.x" ] }, { "name": "Dinerware", "supportedVersions": [ "3.x" ] }, { "name": "Micros 3700", "supportedVersions": [ "RES4", "RES5" ] }, { "name": "Micros Simphony", "supportedVersions": [ "1.6+" ] }, { "name": "Micros First Edition", "supportedVersions": [ "1.6+" ] }, { "name": "EPOS Now", "supportedVersions": [ "All Versions" ] }, { "name": "Maxirest", "supportedVersions": [ "4.9+" ] }, { "name": "Silverware", "supportedVersions": [ "Avrio", "Legacy" ] }, { "name": "OKPOS", "supportedVersions": [ "All Versions" ] }, { "name": "Tiller", "supportedVersions": [ "All Versions" ] }, { "name": "Tango", "supportedVersions": [ "All Versions" ] }, { "name": "Zonal", "supportedVersions": [ "Aztec 3.6+" ] }, { "name": "Lavu", "supportedVersions": [ "All Versions" ] }, { "name": "Bepoz/Vectron", "supportedVersions": [ "4.3+" ] }, { "name": "EasyPos", "supportedVersions": [ "All Versions" ] }, { "name": "IdealPos", "supportedVersions": [ "7.x+" ] }, { "name": "H&L", "supportedVersions": [ "8+" ] } ]; function read (){ for (var i=0; i<json.length; i++){ // console.log('name: ', json[i].name); //to write it in the console // console.log('version: ', json[i].supportedVersions[0]); //to write it in the console document.write(' name: ', json[i].name, "<BR>"); //to write it in html document.write(' version: ', json[i].supportedVersions[0], "<BR><BR>"); //to write it in html } } read(); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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