如何创建和克隆JSON对象? [英] How to create and clone a JSON object?
问题描述
我想知道如何创建JSON(JS)对象然后克隆它.
I was wondering how can I create a JSON (JS) object and then clone it.
推荐答案
如何在javascript/jquery中创建JSON对象?
How to create a JSON object in javascript/jquery?
没有什么像JSON object . JSON表示 JavaScript Object Notation (JavaScript对象表示法),基本上是一个字符串,它编码类似于JavaScript对象常识的信息.
There is nothing like a JSON object. JSON stands for JavaScript Object Notation and is basically a string that encodes information similar to JavaScript's object literals.
但是,您可以使用JSON.stringify(object)
创建这样的编码(这将导致 string ),请参见 JavaScript中的JSON .您也可以手动创建这样的字符串,但是它很容易出错,我不建议这样做.
You can however create such an encoding (which would result in a string) with JSON.stringify(object)
, see JSON in JavaScript. You could also create such a string manually, but it is very error prone and I don't recommend it.
如何在javascript/jquery中克隆JSON对象?
How do I clone a JSON object in javascript/jquery?
因为它只是一个字符串:
As it is just a string:
var jsonString2 = jsonString;
我无法再使用javascript数组
I can`t work anymore with javascript arrays
JSON是交换数据的一种格式,它不是您可以在应用程序中使用的数据结构.
JSON is a format to exchange data, it is not a data structure you can use in an application.
也许您想了解有关 JSON ,对象 JS中的rel ="noreferrer">数组.
Maybe you want to read more about JSON, objects in JS and arrays in JS.
这篇关于如何创建和克隆JSON对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!