最近一项目,要提供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";
}
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";
}
使用JSON处理WebService接口参数
本文介绍如何使用JSON字符串作为WebService接口的参数格式,并通过net.sf.json.JSONObject进行解析。示例代码展示了如何从JSON字符串中获取参数并进行处理。
4275

被折叠的 条评论
为什么被折叠?



