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>

(Later I zip the variable x2 to a json-file)

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.

Related Question How can I edit a manifest.json file from a JS file? How can I allow orientation rotation while using manifest.json? What is the use of manifest.json in React app? Icons and manifest.json Can I use expression in square bracket to access property of class by "this" keyword? Can I access a property from my manifest.json in my extension's JavaScript files? How do I save an array of JSON encoded contents with the square bracket? How do I correctly use square bracket with cdata Use manifest.json in controllers and views (sapui5) How do I set the start_url of a manifest.json to be the root of the site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM