How to create and clone a JSON object?

后端 未结 8 734
独厮守ぢ
独厮守ぢ 2020-12-13 18:04

I was wondering how can I create a JSON (JS) object and then clone it.

8条回答
  •  無奈伤痛
    2020-12-13 18:25

    How to create a JSON object in javascript/jquery?

    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.

    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.

    How do I clone a JSON object in javascript/jquery?

    As it is just a string:

    var jsonString2 = jsonString;
    

    I can`t work anymore with javascript arrays

    JSON is a format to exchange data, it is not a data structure you can use in an application.


    Maybe you want to read more about JSON, objects in JS and arrays in JS.

提交回复
热议问题