使用dojo延迟回调方法读取JSON响应

时间:2014-07-10 19:40:57

标签: javascript json dojo

所以我在网上寻找解决方案,我似乎无法找到答案,因为每个人都在使用getElementById,我不相信这是我问题的正确解决方案。我正在尝试使用这个Javascript函数:

Services.stuff = function() {

function initializer() {
    var deferred = dummyService.getStuff();
    deferred.addCallbacks(callback, errback);
}

function calculateSomething(amount) {
    return Math.round(amount / this.param* 100) / 100;
}

function newThingy(code, param, description) {
      return {
        code: code,
        numbers: param,
        description: description,
         calculateMinutes: calculateMinutes
     }
}

var callback = function(response) {
    for (object in response) {
        //do something.
    }
};

var errback = function(error) {
    //do something.
}

}();

阅读JSON响应。响应是一个包含其他java对象的对象,如下所示:

    {
   "id":1,
   "result":{
      "map":{
         "018004":{
            "param":10,
            "description":"Description",
            "javaClass":"Java Class",
            "code":"018004"
         },
         "018006":{
            "param":11,
            "description":"Description",
            "javaClass":"Java Class",
            "code":"018006"
         },
         "018005":{
            "param":12,
            "description":"Description",
            "javaClass":"Java Class",
            "code":"018005"
         },
      },
      "javaClass":"com.google.common.collect.RegularImmutableMap"
     }
    }

基本上我需要用我的javascript读取该响应然后让javascript返回一个java对象。非常感谢任何帮助。

0 个答案:

没有答案