在 jQuery 中创建 JSON 对象的最佳方法是什么(不使用解析器或 AJAX)?
var JSONobj = new JSON({'a':'b'})
最佳答案
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages...These properties make JSON an ideal data-interchange language.
JSON 是 JavaScript 对象字面量表示法的一个子集。由于 JSON 是 JavaScript 的一个子集,因此它可以毫不费力地在该语言中使用。
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
但是,要从外部源解析 JSON 或从您自己的代码序列化 JSON 对象,您需要一个库,例如 JSON-js因为 Javascript/ECMAScript 目前不支持这个,尽管:
It is expected that native JSON support will be included in the next ECMAScript standard.
关于javascript - 在 jQuery 中制作 JSON 对象的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6404994/