android - How can I get a JSONOBject of a Web Service? -
i'm trying jsonobject of web service. i'm using httpclient httpresponse. when web service return json change return string , try create jsonobject still doesn´t work , return null.
how can ?
import java.io.ioexception; import java.io.serializable; import java.util.list; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.util.entityutils; import org.json.jsonexception; import org.json.jsonobject; public static jsonobject get(string url){ jsonobject jsonobj = null; try { defaulthttpclient httpclient = new defaulthttpclient(); httpresponse httpresponse = httpclient.execute(new httpget(url)); httpentity entity = httpresponse.getentity(); if(entity != null){ string s = entityutils.tostring(entity); jsonobj = new jsonobject(s); } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } return jsonobj; }
Comments
Post a Comment