2013-02-07 34 views
0

我明白我可以插入新的屬性到JSON,像這樣:插入一個新的屬性到JSON

var jsonObj = { 
    members: 
      { 
      host: "hostName", 
      viewers: 
      { 
       user1: "value1", 
       user2: "value2", 
       user3: "value3" 
      } 
     } 
} 

jsonObj.members.viewers["user4"] = "value4"; 

但我需要與之合作的JSON是像這樣(從紋理帕克):

var jsonObj = { 
    "frames": { 
     "chaingun.png": { 
      "frame": { 
       "x": 1766, 
       "y": 202, 
       "w": 42, 
       "h": 34 
      }, 
      "rotated": false, 
      "trimmed": true, 
      "spriteSourceSize": { 
       "x": 38, 
       "y": 32, 
       "w": 42, 
       "h": 34 
      }, 
      "sourceSize": { 
       "w": 128, 
       "h": 128 
      } 
     }   
    } 
} 

我將如何插入一個新的屬性到「框架」?由於語音標記令我感到困惑。

回答

1

你可以簡單地鏈成員像這樣:

jsonObj.frames["chaingun.png"]["frame"]["z"] = 1234; 

// or 

jsonObj.frames["chaingun.png"].frame.z = 4567;