如何最好地使用PHP肥皂与Android? [英] How to best use PHP Soap with Android?
问题描述
我想从PHP中的SOAP的信息,我实现了与在这篇文章中的 Android的SOAP WSDL 。虽然,有一些东西失踪,我想你解释给我,给我一个更好的选择。
I'm trying to get the info from a SOAP in PHP and I achieve that task with the help in this post Android SOAP wsdl. Although, there are a few things missing that I would like you to explain to me and give me a better option.
目前,我的PHP code是:
Currently, my PHP code is:
$query = $db->prepare("SELECT name FROM `oc_category_description`");
$query->execute();
$result = $query->get_result();
$all = array();
while($row = $result->fetch_array(MYSQL_ASSOC)){
$all[] = array_map('utf8_encode', $row);
}
return json_encode($all);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
和Java中的Android我读到这样说:
And in Java Android I read it this way:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object response = (Object) envelope.getResponse();
String strRet = response.ToString();
TextView txt = (TextView)findViewById(R.id.textView1);
txt.setText(strRet);
有了这个code我可以检索的信息,但它不是最好的方式,信息就这样产生了例如:
With this code I can retrieve the info, but it's not the best way, the info comes like this example:
[{'name':'Google'},{'name':'ol\u00f3'},{'name':'yahoo'}]
另外不是被示出这种方式,它带有特殊字符。我想避开他们。
Further than being shown this way, it comes with special characters. And I want to avoid them.
对于我来说最好的办法是这样的code以下(我看到这样的例子遍布谷歌):
For me the best way would be something like the code below (I'm seeing this examples all over Google):
SoapObject response = (SoapObject) envelope.getProperty(0);
因此,我会得到一个数组列表(长度等),我可以管理项目更好。
And therefore I would get an array list (length, etc), and I could manage the items better.
虽然,我已经试过了解决方案,并给我的错误:
Although, I've tried that solution and gives me the error:
7月9日至27日:30:40.094:W / System.err的(3171):java.lang.ClassCastException:
java.lang.String中不能被转换为
org.ksoap2.serialization.SoapObject
9-27 07:30:40.094: W/System.err(3171): java.lang.ClassCastException: java.lang.String cannot be cast to org.ksoap2.serialization.SoapObject
我不认为这个问题可能是在我的PHP,所以我目前正试图无功而返
I do believe that the problem could be on my PHP, so I'm currently trying without success:
$query = $db->prepare("SELECT name FROM `oc_category_description`");
$query->execute();
$query->bind_result($name);
$query->store_result();
$all = array();
while($query->fetch()){
$all[] = array('nome' => $row);
}
$query->close();
$db->close();
return json_encode($all);
你有什么建议?解析当前值,我能得到什么?如果是这样,怎么样?如果我有超过1列,有什么特殊字符的最佳方法?
What do you recommend? Parse the current values I can get? If so, how? And if I have more than 1 column, and what's the best approach for special characters?
感谢大家。
推荐答案
我设法得到这方面的工作是这样的:
I managed to get this working this way:
String strRet = response.toString();
String[] lines = strRet.split(",");
List<String> array_cat = new ArrayList<String>()
for(int i = 0; i <= lines.length - 1; i++){
String cat = lines[i].substring(10, lines[i].length() - 2);
array_cat.add(cat);
}
但我还是有编码的问题。我知道,这个问题是来自PHP,如果任何人有任何解决方案,我AP preciate。
But I'm still with the problem of encoding. I know that the problem comes from PHP, if anyone have any solution, I appreciate.
这篇关于如何最好地使用PHP肥皂与Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!