VDS Renaissance 的界面提供多种语言。官方文档以英语维护,以确保提供统一、一致且始终最新的参考。
JSON
[VDS7]
Syntax
JSON CLOSE, <id>
JSON PARSE, <id>, <text>
JSON LOADFILE, <id>, <filename | url>
JSON SAVEFILE, <id>, <filename> {, PRETTY}
JSON SET, <id>, <path>, <value>
JSON SETRAW, <id>, <path>, <json>
JSON ADD, <id>, <path>, <value>
JSON DELETE, <id>, <path>
JSON CLEAR, <id>
Description
This command is used when working with JSON documents. The document handle <id> is created with @NEW(JSON). The options are:
| JSON CLOSE,... | Releases the JSON document with handle <id>. |
| JSON PARSE,... | Parses the JSON <text> (typically an AI or HTTP response held in a variable) into the document. OK is false if the text is not valid JSON. |
| JSON LOADFILE,... | Loads a document from disk, or from an HTTP/HTTPS URL (a GET request). OK is false if unsuccessful. |
| JSON SAVEFILE,... | Writes the document to <filename>, compact by default or indented if PRETTY is given. |
| JSON SET,... | Sets a string value at <path>, creating any missing objects along the way. |
| JSON SETRAW,... | Sets a raw JSON value at <path> (a number, boolean, object or array). |
| JSON ADD,... | Appends an element to the array at <path> (creating the array if needed). |
| JSON DELETE,... | Removes the key or element at <path>. |
| JSON CLEAR,... | Resets the document to an empty object. |
Paths use the dotted notation described under JSON documents (users.0.name).
OK
As documented above. OK is false (and the document is left unchanged) if a parse fails or a file cannot be read or written. Referring to a document that has not been loaded sets an error.
Example
%h = @new(json)
json set,%h,user.name,John Smith
json setraw,%h,user.age,43
json add,%h,user.roles,admin
json savefile,%h,user.json,PRETTY
json close,%h
See also
- @JSON function
- @NEW function
- JSON Documents
- AI