-
不确定,有待后面验证 webService接口传递json对象数据为什么接口实现类获取不到?
-
我写了一个测试接口,我发布好了之后测试它,我接口里要传递的参数是JSONObject,
我测试客户端传了一个JSONObject类型的对象数据,可是接口实现类获取的为空,我
换成String类型的参数却可以。请问大家传递JSONObject格式的数据,接口方面该怎么写,我现在写的是:接口:
@WebService
public interface IService {
@WebMethod
public void hello( JSONObject username);}
接口实现类:
public class ServiceImp implements IService{
@Override
public void hello(JSONObject username) {
//String abs = username.getString("username");
System.out.println("从客户端获取的参数"+username);}
}
客户端:
public class Client {
public static void main(String[] args) throws MalformedURLException{ // TODO Auto-generated method stub //创建访问wsdl服务地址的url URL url = new URL("http://10.10.10.154:7777/hp?wsdl"); //通过Qname指明服务的具体信息 /* * 第一个参数:接口的包名称,反序 * 第二个参数:实现类名+Service * */ QName qname = new QName("http://webservice.port.ios.com/","ServiceImpService"); //创建服务 Service service = Service.create(url, qname); //实现接口 IService iservice = service.getPort(IService.class); JSONObject jsonobj1 = new JSONObject("{'username':'huangbiao' }"); iservice.hello(jsonobj1); }
}
有些回答: 你不应该传递object,你可以把JSONObject转成成json的String过去,接收后,再把String转换会JSONObject