2

我是 Grails 的新手,所以这可能是一个愚蠢的......但是我正在尝试使用 Grails REST 从 Grails 中的 jquery 客户端获取 json 对象,但我得到了 null。可能是一个小问题,但它对我想要测试的前几个数据流造成了障碍

我的jQuery调用:

var jsonObjects = [{name: "IPAD", input: "IPAD", program: "IPAD", destination: "IPAD",    
priority: "IPAD", userData: "IPAD", email: "IPAD", webCallBackURL: "IPAD", copyToLocal:    
"IPAD", scriptPreProcess: "IPAD", deleteSource: "IPAD", moveToSource: "IPAD",    
scriptPostProcess: "IPAD", inputImage: "IPAD", leftImage: "IPAD", topImage: "IPAD", 
opacityImage: "IPAD", bImageAdAvBlanking: "IPAD"}] 

$.ajax({ 
    type: "POST", 
    url: 'http://localhost:8080/Medusa/jobControlREST/save', 
    data: {ipad: JSON.stringify(jsonObjects)}, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    beforeSend: function(x) { 
        if (x && x.overrideMimeType) { 
            x.overrideMimeType("application/json;charset=UTF-8?"); 
        } 
    },
    success: function() { 
        alert('hi'); 
    } 
}); 

我的圣杯:

def save = { 
    def jsonString = params['ipad'] //returns null 
    def json = JSON.parse(jsonString) // returns null obviously 
    println "this is POST call" +json // gets printed but json is null...sign ( 
} 

urlmapping: 
    "/$controller/$action?/$id?"(parseRequest:true) {
        constraints { 
            action = [GET:"index", POST:"save", PUT:"update", DELETE:"remove"] 
        }
    }
4

1 回答 1

0

用这个:

def jsonObject=request.JSON
于 2016-04-01T23:43:48.827 回答