반응형

javascript 객체를 JSON 객체로 변환하는 함수.

JSON.parse() : JSON 형태 문자열을 자바스크립트 객체로 변환

JSON.stringify() : 자바스크립트 객체를 JSON 형슥으로 변환

  1. <script type="text/javascript">
  2.     var obj = {
  3.         name : "TEST",
  4.         gender : "Male"
  5.     };
  6.     console.log(obj);
  7.     console.log(JSON.stringify(obj));
  8.  
  9.     var date = new Date();
  10.  
  11.     console.log(date);
  12.     console.log(date.toJSON());
  13.     console.log(JSON.stringify(date));
  14.     console.log(JSON.stringify(date.toJSON()));
  15. </script>

결과값

Object {name: "TEST", gender: "Male"} test.html:10
{"name":"TEST","gender":"Male"} test.html:11
Fri May 10 2013 08:59:51 GMT+0900 (대한민국 표준시) test.html:15
2013-05-09T23:59:51.036Z test.html:16
"2013-05-09T23:59:51.036Z" test.html:17
"2013-05-09T23:59:51.036Z"

정말 요즘 javascript, jquery때문에 헷갈려 죽겠다. ㅠㅠ

728x90
반응형

'Development > Frontend skills' 카테고리의 다른 글

React 에서 props 사용  (0) 2017.01.09
React.. 끄적끄적.  (0) 2017.01.09
Mac 에서 Node.js 설치  (0) 2017.01.05
jquery radio button 속성 설정  (0) 2013.09.04
JavaScript var Scope  (0) 2013.03.15
반응형

가끔 이런것이 필요할 때가 있다.

userId 를 USER_ID 로 바꾸는 기능.

  1. public class Test {
  2.     public static void main(String[] args) throws Exception {
  3.         String regex = "([a-z])([A-Z])";
  4.         String replacement = "$1_$2";
  5.                 String str = "UserId";
  6.                 String value = "";
  7.                 value = str.replaceAll(regex, replacement).toUpperCase();
  8.                 System.out.println(value);
  9.     }
  10. }

728x90
반응형

'Development > Java' 카테고리의 다른 글

Meta Annotaion  (0) 2013.07.01
Type-Safe Code란?  (0) 2013.06.25
Tomcat 구동시 라이브러리를 못찾을 경우..  (0) 2013.03.29
ExecutorService  (0) 2013.03.22
오버라이딩 규칙  (0) 2013.02.12

+ Recent posts