好的,我正在使用js编写一个Web操作系统。我正在使用JSON作为文件系统。我已经在网上寻找关于JSON内容的教程约一周,但是我无法找到有关从Web页面编写JSON文件的任何内容。我需要在文件中创建新对象,而不是更改现有对象。以下是我的代码:
{"/": {
"Users/": {
"Guest/": {
"bla.txt": {
"content":
"This is a test text file"
}
},
"Admin/": {
"html.html": {
"content":
"yo"
}
}
},
"bin/": {
"ls": {
"man": "Lists the contents of a directory a files<br/>Usage: ls"
},
"cd": {
"man": "Changes your directory<br/>Usage: cd <directory>"
},
"fun": {
"man": "outputs a word an amount of times<br/>Usage: fun <word> <times>"
},
"help": {
"man": "shows a list of commands<br/>Usage: help"
},
"clear": {
"man": "Clears the terminal<br/>Usage: clear"
},
"cat": {
"man": "prints content of a file<br/>Usage: cat <filename>"
}
},
"usr/": {
"bin/": {
},
"dev/": {
}
}
}}
JSON.parse
解析它,像处理其他JavaScript对象一样进行修改,然后再使用JSON.stringify
重新编码。 - James M