我正在尝试发送一个json String但是当我调用WebService时,他发送一个null参数而不是我的字符串。 当我去调试时,我可以在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;
}
}
答案 0 :(得分:0)
这是NAMESPACE。它不应该有/最终。所以命名空间是http://serv.lageo.ufpr.br而不是http://serv.lageo.ufpr.br/ ...