javascript/ html/ json/ minecraft
I try to create a manifest with JavaScript but minecraft can't read the right and left square bracket from JavaScript. What can I do so that minecraft is able to read the right and left square bracket?
function create() { var x = document.getElementsByTagName("INPUT"); var x2 = '{\n"header": {\n"version": [\n0,\n0,\n1\n],\n"description": "' + x[1].value + '",\n"name": "' + x[0].value + '",\n"uuid": "' + x[2].value + '"\n},\n"modules": [\n{\n"version": [\n0,\n0,\n1\n],\n"description": "",\n"type": "resources",\n"uuid": "' + x[3].value + '"\n}\n],\n"format_version": 1\n}'; console.log(x2); }
Name: <input><br> Discription: <input><br> UUID: <input><br> UUID2: <input><br> <button onclick="create()">Create</button>
Instead of building a json-link string, you most likley want to use JSON.stringify
here.
function create() { var x = document.getElementsByTagName('INPUT'); var output = { header: { version: [0, 0, 1], description: x[1].value, name: x[0].value, uuid: x[2].value, }, modules: [ { version: [0, 0, 1], description: '', type: 'resources', uuid: x[3].value, }, ], format_version: 1, }; console.log(JSON.stringify(output, null, 2)); }
Name: <input><br> Discription: <input><br> UUID: <input><br> UUID2: <input><br> <button onclick="create()">Create</button>
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.