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.
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();
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);
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.
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:
9-27 07:30:40.094: W/System.err(3171): java.lang.ClassCastException: java.lang.String cannot be cast to org.ksoap2.serialization.SoapObject
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);
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?
Thank you all.