프론트엔드/Java Script, jQuery, AJAX
[Ajax] Json으로 데이터 가져오기.
데르벨준
2014. 1. 6. 22:53
반응형
AjaxTest.html
test.jsp <-- jsonsimple로 만듬
test.html
[ {"name": "lioncat", "age": 14, "nickname": "qwerty"} ]
test.jsp <-- jsonsimple로 만듬
jsonsimple download --> https://code.google.com/p/json-simple/downloads/list
라이브러리 파일은 톰캣 기준으로 WEB-INFO/lib/ 밑에 둔다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="org.json.simple.*"%> <% String name = request.getParameter("name"); JSONArray jArray = new JSONArray(); JSONObject jObject = new JSONObject(); jObject.put("name", name); jObject.put("age", "14"); jObject.put("nickname", "qwerty"); jArray.add(0, jObject); out.println(jArray.toJSONString()); System.out.println(jArray.toJSONString()); %>
반응형