[已解决]cocostudio的json解析失败?

GUIReader.js 823

var widgetTree = jsonDict"widgetTree"]; var widget = this.widgetFromJsonDictionary(widgetTree);
该函数里面

var classname = data"classname"];
导致报异常 Uncaught TypeError: Cannot read property ‘classname’ of undefined

因为生成的json文件根本没有widgetTree,只有nodeTree。
这是bug吗?还是我用的不对?

cocostudio 版本为1.0.0.0 beta mac版本。

json文件如下:

{
  "version": "1.0.0.0",
  "designWidth": 480,
  "designHeight": 320,
  "dataScale": 1.0,
  "textures": ],
  "texturesPng": 
    "/Applications/Cocos Studio.app/Contents/MacOS/EditorDefaultRes/GUI/loadingbar.png",
    "/Applications/Cocos Studio.app/Contents/MacOS/EditorDefaultRes/GUI/button.png"
  ],
  "nodeTree": {
    "options": {
      "$type": "EditorCommon.JsonModel.Component.GUI.RootGUISurrogate, EditorCommon",
      "visible": true,
      "frameEvent": null,
      "name": "Node",
      "classname": "Node"
    },
    "children": 
      {
        "options": {
          "$type": "EditorCommon.JsonModel.Component.GUI.PanelSurrogate, EditorCommon",
          "bgColorR": 202,
          "bgColorG": 209,
          "bgColorB": 210,
          "bgColorOpacity": 255,
          "touchAble": true,
          "visible": true,
          "classType": "Panel",
          "width": 480.0,
          "height": 320.0,
          "sizePercentX": 1.0,
          "sizePercentY": 1.0,
          "actionTag": 879531657,
          "tag": 1,
          "anchorPointX": 0.0,
          "anchorPointY": 0.0,
          "name": "Panel_2",
          "classname": "Panel"
        },
        "children": 
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.LoadingBarSurrogate, EditorCommon",
              "textureData": {
                "resourceType": 0,
                "path": "GUI/loadingbar.png",
                "plistFile": ""
              },
              "x": 231.0,
              "y": 293.0,
              "visible": true,
              "classType": "LoadingBar",
              "width": 350.0,
              "height": 24.0,
              "positionPercentX": 0.48125,
              "positionPercentY": 0.915625,
              "sizePercentX": 0.7291667,
              "sizePercentY": 0.075,
              "actionTag": 47371762,
              "tag": 2,
              "ignoreSize": true,
              "name": "barProgress",
              "classname": "LoadingBar"
            },
            "children": ],
            "classname": "LoadingBar"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.LabelBMFontSurrogate, EditorCommon",
              "fileNameData": {
                "resourceType": 0,
                "path": "GUI/missing-font.fnt",
                "plistFile": ""
              },
              "text": "1234567890qwertyuiopasdfghjklzxcvbnm",
              "x": 221.0,
              "y": -33.0,
              "visible": true,
              "classType": "LabelBMFont",
              "width": 906.0,
              "height": 37.0,
              "positionPercentX": 0.460416675,
              "positionPercentY": -0.103125,
              "sizePercentX": 0.489583343,
              "sizePercentY": 0.115625,
              "actionTag": 754308123,
              "tag": 32,
              "ignoreSize": true,
              "name": "LabelBMFont_5",
              "classname": "LabelBMFont"
            },
            "children": ],
            "classname": "LabelBMFont"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.LabelAtlasSurrogate, EditorCommon",
              "charMapFileData": {
                "resourceType": 0,
                "path": "GUI/labelatlasimg.png",
                "plistFile": ""
              },
              "startCharMap": "0",
              "x": -67.0,
              "y": 15.0,
              "scaleX": 0.1583333,
              "scaleY": 1.18750036,
              "visible": true,
              "classType": "LabelAtlas",
              "width": 240.0,
              "height": 32.0,
              "positionPercentX": -0.139583334,
              "positionPercentY": 0.046875,
              "sizePercentX": 0.5,
              "sizePercentY": 0.1,
              "actionTag": 413334426,
              "tag": 33,
              "ignoreSize": true,
              "name": "LabelAtlas_6",
              "classname": "LabelAtlas"
            },
            "children": ],
            "classname": "LabelAtlas"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon",
              "text": "",
              "areaWidth": 94.0,
              "areaHeight": 32.0,
              "x": 146.0,
              "y": 146.0,
              "scaleX": 1.68150723,
              "scaleY": 1.56345785,
              "visible": true,
              "classType": "Label",
              "width": 94.0,
              "height": 32.0,
              "positionPercentX": 0.304166675,
              "positionPercentY": 0.45625,
              "sizePercentX": 0.19583334,
              "sizePercentY": 0.1,
              "actionTag": 249651874,
              "tag": 4,
              "name": "lblFormula",
              "classname": "Label"
            },
            "children": ],
            "classname": "Label"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.TextFieldSurrogate, EditorCommon",
              "text": "",
              "placeHolder": "?",
              "areaWidth": 89.0,
              "areaHeight": 32.0,
              "x": 285.0,
              "y": 146.0,
              "scaleY": 1.37499976,
              "touchAble": true,
              "visible": true,
              "classType": "TextField",
              "width": 89.0,
              "height": 32.0,
              "positionPercentX": 0.59375,
              "positionPercentY": 0.45625,
              "sizePercentX": 0.185416669,
              "sizePercentY": 0.1,
              "actionTag": 1013062844,
              "tag": 5,
              "name": "tfAnswer",
              "classname": "TextField"
            },
            "children": ],
            "classname": "TextField"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.ButtonSurrogate, EditorCommon",
              "normalData": {
                "resourceType": 0,
                "path": "GUI/button.png",
                "plistFile": ""
              },
              "pressedData": {
                "resourceType": 0
              },
              "disabledData": {
                "resourceType": 0
              },
              "text": "确定",
              "capInsetsWidth": 1.0,
              "capInsetsHeight": 1.0,
              "scale9Width": 103.0,
              "scale9Height": 40.0,
              "x": 395.0,
              "y": 146.0,
              "touchAble": true,
              "visible": true,
              "classType": "Button",
              "width": 103.0,
              "height": 40.0,
              "positionPercentX": 0.8229167,
              "positionPercentY": 0.45625,
              "sizePercentX": 0.214583337,
              "sizePercentY": 0.125,
              "actionTag": 540337571,
              "tag": 6,
              "ignoreSize": true,
              "name": "btnOk",
              "classname": "Button"
            },
            "children": ],
            "classname": "Button"
          },
          {
            "options": {
              "$type": "EditorCommon.JsonModel.Component.GUI.LabelSurrogate, EditorCommon",
              "text": "",
              "areaWidth": 94.0,
              "areaHeight": 32.0,
              "x": 224.0,
              "y": 232.0,
              "scaleX": 3.65955,
              "scaleY": 1.25231719,
              "visible": true,
              "classType": "Label",
              "width": 94.0,
              "height": 32.0,
              "positionPercentX": 0.466666669,
              "positionPercentY": 0.725,
              "sizePercentX": 0.19583334,
              "sizePercentY": 0.1,
              "actionTag": 247174576,
              "tag": 3,
              "name": "lblTitle",
              "classname": "Label"
            },
            "children": ],
            "classname": "Label"
          }
        ],
        "classname": "Panel"
      }
    ],
    "classname": "Node"
  },
  "action": {
    "speed": 1.0,
    "timelines": ]
  }
}


```

Cocos2d-js 暂时还不支持mac版本的Cocostudio哦。 建议楼主换成windows版本的。 可用范围在 1.2-15.0.1版本

知道原因了。原来cocostudio mac 1.0 beta版本只支持 cocos2d js 3.2, 我现在是3.0,所以二者不兼容。

详见:
http://www.cocoachina.com/bbs/read.php?tid=213574

谢谢!
看来这些配套工具的版本应该给个说明。

恩恩。文档部分我们在努力完善中。