import
java.io.IOException;
import
java.util.ArrayList;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import
org.codehaus.jettison.json.JSONArray;
import
org.codehaus.jettison.json.JSONException;
import
org.codehaus.jettison.json.JSONObject;
import
kr.co.techinmotion.web.IAction;
public
class
JsonDismantleAction
implements
IAction {
private
boolean
redirect =
false
;
@Override
public
String process(HttpServletRequest request,
HttpServletResponse response)
throws
ServletException, IOException {
String jsonText = request.getParameter(
"jsonText"
);
String name =
null
;
String age =
null
;
ArrayList<STRING> locationArray =
new
ArrayList<STRING>();
try
{
JSONObject jo =
new
JSONObject(jsonText);
name = jo.getString(
"이름"
);
age = jo.getString(
"나이"
);
JSONArray array = jo.getJSONArray(
"위치"
);
for
(
int
i=
0
; i < array.length(); i++){
JSONObject jsonObject = array.getJSONObject(i);
String lat = jsonObject.getString(
"위도"
);
String lon = jsonObject.getString(
"경도"
);
locationArray.add(i,
"위도 : "
+ lat +
", 경도 : "
+ lon);
}
}
catch
(JSONException e) {
e.printStackTrace();
}
request.setAttribute(
"name"
, name);
request.setAttribute(
"age"
, age);
request.setAttribute(
"locationArray"
, locationArray);
return
"/WEB-INF/jsonResult.jsp"
;
}
@Override
public
boolean
isRedirect() {
return
redirect;
}
}