Android:json_encode to array - 非关联数组

时间:2013-09-10 16:41:12

标签: java android arrays json

我的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

1 个答案:

答案 0 :(得分:0)

首先使用ResponseHandler,然后您将在字符串中有响应,然后按照过程

转换为数组
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
JSONArray test = new JSONArray(responseBody);
String[] resultingArray = test.join(",").split(",");