0

我的 php 文件有这个输出:

echo json_encode(array("value0","value1","value2"));

如何在 Android 中将此响应作为数组获取?

HttpResponse response = httpclient.execute(httppost);                       
String[] resultArray = ?

我希望有:

resultArray[0] --> value0
resultArray[1] --> value1
resultArray[2] --> value2
4

1 回答 1

0

首先使用 ResponseHandler,然后您将在字符串中获得响应,然后通过以下过程转换为数组

ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
JSONArray test = new JSONArray(responseBody);
String[] resultingArray = test.join(",").split(",");
于 2013-09-10T17:07:15.453 回答