我正在尝试从服务器获取 JSON 值。我不知道我的代码有什么问题。我正在使用AsyncTask,这是我的代码doInBackground
代码:
@Override
protected Void doInBackground(List<String>... articlesRec) {
for (List<String> articlesPostValue : articlesRec) {
event = articlesPostValue.get(0);
category = articlesPostValue.get(1);
paged = articlesPostValue.get(2);
deviceID = articlesPostValue.get(3);
}
List<NameValuePair> articlesPostValues = new ArrayList<NameValuePair>();
articlesPostValues.add(new BasicNameValuePair("_event", event));
articlesPostValues.add(new BasicNameValuePair("cat", category));
articlesPostValues.add(new BasicNameValuePair("paged", paged));
articlesPostValues.add(new BasicNameValuePair("_deviceID", deviceID));
HttpClient hc = new DefaultHttpClient();
HttpPost hp = new HttpPost(AutoLifeConstants.BASE_URL);
try {
hp.setEntity(new UrlEncodedFormEntity(articlesPostValues));
// Execute HTTP Post Request
HttpResponse response = hc.execute(hp);
String result = EntityUtils.toString(response.getEntity());
String jsontext = new …Run Code Online (Sandbox Code Playgroud)