Change key name in nested JSON structure

前端 未结 3 1604
名媛妹妹
名媛妹妹 2020-12-10 18:53

I have a JSON data structure as shown below:

{
    \"name\": \"World\",
    \"children\": [
      { \"name\": \"US\",
          \"children\": [
           {          


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 19:49

    You could use a function like this :

    function clonerename(source) {
        if (Object.prototype.toString.call(source) === '[object Array]') {
            var clone = [];
            for (var i=0; i

    Note that what you have isn't a JSON data structure (this doesn't exist as JSON is a data-exchange format) but probably an object you got from a JSON string.

提交回复
热议问题