天天看點

[] webservice參數用json的字元串格式傳遞

最近一項目,要提供webservice接口,本人用json字元串做完接口方法參數格式,不知道是否可行,高人指點一下,小弟在此謝過,然後用net.sf.json.jsonobject解析參數,要求參數格式為{'name':'get','int':1,'double',1.1,'null':null}。具體代碼如下:

public string processservice(string data){

map map = null;

try {

jsonobject jsonobject = jsonobject.fromobject(data);

map = new hashmap();

for (iterator iter = jsonobject.keys(); iter.hasnext();) {

string key = (string) iter.next();

map.put(key, jsonobject.get(key));

}

} catch (exception e) {

return "傳人的資料格式有誤";

}

//處理傳入資料

return "success";

}