How to return PHP array and receive it with Java -
How to return PHP array and receive it with Java -
i have on webservice:
function listar($username) { $result = mysql_query("select name apks tipo=0"); //$registo = mysql_fetch_array($result); $numero = 0; while($registo = mysql_fetch_array($result)) { $regs[$numero] = $registo['name']; $numero++; } homecoming $regs; //return mysql_fetch_array($result); } in java, after soap phone call (not relevant now) read way:
object response = envelope.getresponse(); string x = response.tostring(); i need access 1 of fields (selected database) thought, why not split array strings?
i tried 2 methods:
string[] arr=x.split(" "); system.out.println("array :"+arr.length); for(int i=0;i<arr.length;i++) { .. } stringtokenizer starr=new stringtokenizer(x," "); while(starr.hasmoretokens()) { ... } but none of them worked, whick create me believe i'm returning badly array in first place.
any help?
update:
so i'm using 1 time again xsd:string;
now have on webservice homecoming json_encode($regs);
to convert object response i'm using specific google api http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/
object response = envelope.getresponse(); gson gson = new gson(); string jstring = gson.tojson(response);
but i'm difficulty parsing "jstring" because it's format: "[\"something\",\"something\",\"something\",\"something\",.....]". have not identifier values.
how can extract dynamic values , assign them string[]?
use:
json_encode($array); in php
and
jsonobject in java read.
see example: http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
update
change line:
$regs[$numero] = $registo['name']; to:
$regs[] = array('name' => $registo["name"]); if need id, can do:
$regs[] = array('name' => $registo["name"], 'id' => $registo["id"]); forget:
the mysql_fetch_array returns real array not string. it's not needed split string.
be sure php web service returning xsd:array generate new proxy using generator http://www.soapui.org. utilize proxy. nil else. java php
Comments
Post a Comment