我正在尝试发送一个 json 字符串,但是当我调用 WebService 时,他发送了一个空参数而不是我的字符串。当我去调试时,我可以在soapObject Propertis 上看到我的json。但是在我的 webService 中,当我从我的 andoid 应用程序调用时,他总是返回 null
if (json.Equals(null)) {
return "null";
}
try {
return json;
root = JObject.Parse(json);
} catch (Exception e) {
return e.StackTrace;
}
return "parseok";
这是我正在使用的代码。
public class OpcoesActivity extends Activity implements OnClickListener {
private String cpf;
private String senha;
private PontosUsuarioDAO pdao = new PontosUsuarioDAO(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.opcoeslayout);
cpf = getIntent().getStringExtra("cpf");
senha = getIntent().getStringExtra("senha");
Button importar = (Button) findViewById(R.id.bt_importar);
importar.setOnClickListener(this);
Button exportar = (Button) findViewById(R.id.bt_exportar);
exportar.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_importar:
Intent i = new Intent(this, SincronizarActivity.class);
i.putExtra("cpf", cpf);
i.putExtra("senha", senha);
startActivity(i);
break;
case R.id.bt_exportar:
new Thread(new Runnable() {
public void run() {
Gson gson = new Gson();
final String json = gson.toJson(pdao.exportaPontosUsuario(cpf));
ExportarDados exp = new ExportarDados("{\"teste\":\"java\"}");
String b = exp.ExportaDadosUser();
}
}).start();
break;
}
}
}
这是导出的类
public class ExportarDados {
private static final String SOAP_ACTION = "http://serv.lageo.ufpr.br/EnviaPontosUsuario";
private static final String METHOD_NAME = "EnviaPontosUsuario";
private static final String NAMESPACE = "http://serv.lageo.ufpr.br/";
private static final String URL = "http://200.17.203.150/Caderneta/Sincronizar.asmx";
private String json;
private SoapObject soapObject;
private String result = "";
public ExportarDados(String json) {
this.json = json;
}
public String ExportaDadosUser() {
String e2;
try {
soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("json", json);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(soapObject);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
result = resultString.toString();
} catch(Exception e) {
e.printStackTrace();
}
return result;
}
}