HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://my.server:8080/android/service.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("action", "getjson"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
service.php
生成json字符串.我怎么才能从我的response
里拿到呢?顺便说一句,我已经封锁了GSON
库,也许我可以使用其中的任何方法呢?
与此类似的解决方案看起来相当丑陋,imo:best way to handle json from httpresponse android
There much be better ways, right?
Any help is appreciated, thanks
Update:
String json = EntityUtils.toString(response.getEntity());
看起来很管用.只有一个小问题:绳子用括号[]
Package.我应该手动移除它们吗?它们是由php:s json_encode()
生成的