php - getting http response in separate strings -
i have stored longitude , latitude in database , getting them through http request in form of single string. want start map activity takes longitude , latitude server response , put marker @ point. problem can't how separate longitude , latitude returned in single string server. here activity:
public class signin extends asynctask<string,void,string> { private context context; private textview rolefield; private context context1; public signin(context context) { this.context = context; } protected void onpreexecute() {} @override protected string doinbackground(string... arg0) { try { string bus_id = (string) arg0[0]; string link = "http://mysystem_ip/routes.php?bus_id=" + bus_id + ""; url url = new url(link); httpclient client = new defaulthttpclient(); httpget request = new httpget(); request.seturi(new uri(link)); httpresponse response = client.execute(request); bufferedreader in = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); stringbuffer sb = new stringbuffer(""); string line = ""; while ((line = in.readline()) != null) { sb.append(line); break; } in.close(); return sb.tostring(); } catch (exception e) { return new string("exception: " + e.getmessage()); } } @override protected void onpostexecute(string result) { this.rolefield.settext(result); intent i1 = new intent (context, mapsactivity.class); i1.putextra("result",result); context.startactivity(i1); } }
the quick , dirty way split string this:
string response = "31.578369901154527 74.35708886792317"; string[] responseparts = response.split(" "); string firstpart = responseparts[0]; string secondpart = responseparts[1]; log.d("split response", "first: "+firstpart+" second: "+secondpart);
this code of course assumes delimiter separating 2 parts of string blank space " "
-- long won't change, should able split response string pretty using code above.
Comments
Post a Comment