php
function getPath1List() {
$dir='00';
$files = scandir($dir);
$file_path1 = array();
$file_path1["categories"] = array();
foreach($files as $ind_file) {
$tmp = array();
$tmp["filePath1"] = $ind_file;
array_push($file_path1["categories"], $tmp);
}
header('Content-Type: application/json');
echo json_encode($file_path1);
}
getPath1List();
결과값은
{"categories":[{"filePath1":"."},{"filePath1":".."},{"filePath1":"2016_04_20"},{"filePath1":"2016_04_21"},{"filePath1":"2016_04_22"},{"filePath1":"2016_04_23"},{"filePath1":"2016_04_24"},{"filePath1":"2016_04_25"},{"filePath1":"2016_04_26"}
android에서 데이터값을 받아오기위해서 사용한 util은
get & set 용
public class Category {
private String filePath1;
public Category(){}
public Category(String filePath1) {
this.filePath1 = filePath1;
}
public String getFilePath1() {
return filePath1;
}
public void setFilePath1(String filePath1) {
this.filePath1 = filePath1;
}
}
유틸
public class ServiceHandler {
static InputStream is = null;
static String file_path1 = null;
public final static int GET = 1;
public final static int POST = 2;
public ServiceHandler() {
}
public String makeServiceCall(String url, int method) {
return this.makeServiceCall(url, method, null);
}
public String makeServiceCall(String url, int method,
List<NameValuePair> params) {
try {
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
// Checking http request method type
if (method == POST) {
HttpPost httpPost = new HttpPost(url);
// adding post params
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params));
}
httpResponse = httpClient.execute(httpPost);
} else if (method == GET) {
// appending params to url
if (params != null) {
String paramString = URLEncodedUtils
.format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
file_path1 = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error: " + e.toString());
}
return file_path1;
}
}
게시판 제한때문에 나머지부분은 댓글로남기겠습니다.