레이블이 JSON인 게시물을 표시합니다. 모든 게시물 표시
레이블이 JSON인 게시물을 표시합니다. 모든 게시물 표시

2017년 6월 20일 화요일

JSON 관련 함수

JSON.parse() <->JSON.stringfy()와 서로 반대개념
A common use of JSON is to exchange data to/from a web server.
When receiving data from a web server, the data is always a string.
Parse the data with JSON.parse(), and the data becomes a JavaScript object.

Example - Parsing JSON

Imagine we received this text from a web server:
'{ "name":"John", "age":30, "city":"New York"}'
Use the JavaScript function JSON.parse() to convert text into a JavaScript object:
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

2016년 12월 14일 수요일

JSON 간단 예제

--JAVA 부분
@RequestMapping(value="/financeList", method=RequestMethod.GET)
public String financeList(ModelMap modelMap){

        JSONObject obj = new JSONObject();
        obj.put("Test", "New");
        obj.put("Test1", "New1");
       
        JSONArray arr = new JSONArray();
        arr.put(12);
        arr.put(122);
        arr.put(453);
        arr.put(123);
       
        obj.put("NumberList", arr);
       
        System.out.println(obj.toString());
       
        modelMap.put("json", obj.toString());
       
        return "jsonTest";
}

--JSP 부분

<jsp:directive.page contentType="text/html;charset=UTF-8" />${json}