사진2008. 6. 26. 03:22
사용자 삽입 이미지


그동안 은서가 커서 100일 사진을 찍었다... 다른 사진이 더 이쁘긴 한데 이 사진이 젤 먼저 왔다...

100일 사진을 무려 4번에 걸쳐서 찍었다...

울 은서가 카메라 의식을 확실히 하는데 모자 쓰는게 싫었납다... 가서 사진만 찍을라구 하면 운다...

아무래도 집에 조명세트 사서 집에서 찍어줘야겠다... 언제나 찍을수 있게....

물론 이번에 찍은 100일 사진이 겁나게 비싼것도 한 몫했다.. -_-;;;

분당 블루오션 스튜디오에서 찍었는데 사진이 맘에 들긴 하는데 비용이... 대략 OTL 이다...

그냥 조명세트 하나 사고 만다... -_-

암튼 울 은서는 너무 이쁘게 자라고 있다....

뒤집기는 기본으로 하고... 잼잼도 한다.. 캬하하~~~ 얼마나 귀여운지...

벌써 낯가림을 시작했고 아빠, 엄마, 맘마, 할무이 소리도 곧잘 한다..

발음이 비슷비슷하긴 하지만.. ㅋㅋㅋ 그래도 확실히 구분할수 있다..... 내 아가라 그런가? ㅎㅎㅎ

암튼 요즘엔 울 은서 보는 맛에 산다...

'사진' 카테고리의 다른 글

에버랜드 고고싱 (2008-11-02)  (0) 2008.12.04
용문산 단풍구경 (2008-10-18)  (0) 2008.12.04
은서가 이만큼 컸당!  (2) 2008.11.06
은서 100일 사진  (2) 2008.06.26
은서 50일 사진  (1) 2008.06.26
우리 가족 사진..  (0) 2008.06.26
Posted by 양군이당
TAG 100일, 은서

댓글을 달아 주세요

  1. 눈 완죤 양군이다!! ㅋㅋ
    이뽀이뽀~

    2008.06.27 12:20 [ ADDR : EDIT/ DEL : REPLY ]
  2. 재무니

    ㅋ귀엽네용~

    2008.06.27 16:28 [ ADDR : EDIT/ DEL : REPLY ]

사진2008. 6. 26. 03:17
사용자 삽입 이미지

울 은서 50일 사진이다...

너무 귀엽지 않은가? ㅋㅋ 컴쟁이들 다 딸 낳는다고 서러워 하지 말라....

아들도 물론 이쁘겠지만.. 울 딸 보면 너무너무 이쁘다... 딸 자랑에 팔불출 되도 좋다..

이 사진 보고 안 부러워 할 총각 개발자 있음 나오보시라...

'사진' 카테고리의 다른 글

에버랜드 고고싱 (2008-11-02)  (0) 2008.12.04
용문산 단풍구경 (2008-10-18)  (0) 2008.12.04
은서가 이만큼 컸당!  (2) 2008.11.06
은서 100일 사진  (2) 2008.06.26
은서 50일 사진  (1) 2008.06.26
우리 가족 사진..  (0) 2008.06.26
Posted by 양군이당
TAG 50일, 은서

댓글을 달아 주세요

  1. 귀여워~~^^

    2008.08.22 16:24 신고 [ ADDR : EDIT/ DEL : REPLY ]

사진2008. 6. 26. 03:13
사용자 삽입 이미지
사용자 삽입 이미지


울 아가 은서랑 마눌 써니랑 양군의 가족 사진...

뭐 50일 사진도 찍었고 100일 사진도 찍었지만

이게 젤 처음 만든 가족 사진이랄까? ㅋㅋ

'사진' 카테고리의 다른 글

에버랜드 고고싱 (2008-11-02)  (0) 2008.12.04
용문산 단풍구경 (2008-10-18)  (0) 2008.12.04
은서가 이만큼 컸당!  (2) 2008.11.06
은서 100일 사진  (2) 2008.06.26
은서 50일 사진  (1) 2008.06.26
우리 가족 사진..  (0) 2008.06.26
Posted by 양군이당

댓글을 달아 주세요

자바/SE2008. 6. 26. 02:28
원문 http://blog.naver.com/gospeler/130005477947

 CallableStatement cstmt = null;


 try {


    // 프로시저 콜

    cstmt = con.prepareCall("{call procedureName(?, ?)}");


    // IN parameter설정
    cstmt.setString(1, ?);


    // Out parameter의 Type설정
    cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);


    cstmt.execute();


    // Out parameter의 값을 얻고, 출력한다.
    System.out.println("result : " + c.getString(2));


 } catch(Exception e) {


    e.printStackTrace();
    throw e;


 } finally {


    if(cstmt != null) try { cstmt.close(); } catch(Exception ignore) {}


 }

Posted by 양군이당

댓글을 달아 주세요

자바/SE2008. 6. 26. 02:27
원문 http://cafe.naver.com/intolicense/777 Oracle의 Stored Procedure/Function 이용하기 (CallableStatement)  


==============================================
Oracle의 Stored Procedure/Function 이용하기  
==============================================

CallableStatement

모든 DBMS들에 대한 표준방법으로 저장 프로시져(stored procedure)를 호출하는 방법을 제공한다.
두가지 형태중의 하나인 escape 문법으로 작성되어진다.  즉, 결과 매개변수를 가지는 형태와 결과 매개변수가 없는 형태
결과 매개변수를 리턴하는 프로시져를 위한 문법은 다음과 같다.:  
{? = call procedure_name[(?, ?, ...)]} 매개변수가 없는 저장 프로시져를 위한 문법은 다음과 같을 것이다. :  
{call procedure_name}  


CallableStatement 객체는 Connection의 prepareCall 메쏘드에 의해 생성된다.  아래의 예제는 저장 프로시져 getTestData의 호출을 포함하는 CallableStatement의 인스턴스를 만든다.  이것은 두 개의 인자들을 가지고 있고 결과 매개변수는 없다.:  
   CallableStatement cstmt = con.prepareCall("{call getTestData(?, ?)}");  


CallableStatement 객체로 IN 매개변수를 넘겨주는 것은 PreparedStatement로부터 상속받은 setXXX 메쏘드이다. 넘겨질 값의 데이터형은 사용할 setXXX 메쏘드를 결정한다.(setFloat는 float 값을 넘겨준다.등등)    만약 저장 프로시져가 OUT 매개변수를 리턴한다면, 각 OUT 매개변수의 SQL형은 CallableStatement 객체를 실행할 수 있기 전에 등록되어져야 한다.(이것은 몇몇 DBMS들이 SQL형을 필요로 하기 때문에 필요하다.)  SQL형을 등록하는 것은 registerOutParameter 메쏘드를 사용한다.  


다음의 예제는 유일한 매개변수로 INOUT 매개변수를 가지고 있는 저장 프로시져 reviseTotal이 있다는 것을 가정한다. setByte 메쏘드는 매개변수를 25로 설정하며, 이것은 드라이버가 SQL TINYINT로써 데이터베이스에 전송할 것이다. 그런다음 registerOutParameter는 SQL TINYINT로써 매개변수를 등록한다. 저장 프로시져가 실행된 후에, 새로운 SQL TINYINT 값을 리턴하고, getByte 메쏘드는 이 새로운 값을 자바 byte로 검색할 것이다.  
CallableStatement cstmt = con.prepareCall("{call reviseTotal(?)}");  
      cstmt.setByte(1, 25); cstmt.registerOutparameter(1, java.sql.Types.TINYINT); cstmt.executeUpdate(); byte x = cstmt.getByte(1);  




------------------------------
CallableStatement 예제
------------------------------

/* Oracle Server에 작성된 Function */

function employ_age (v_name in employees.name%TYPE) return number
is
v_age number(3) := 0;
begin
  select age into v_age from employees
  where  name = v_name;
  return v_age;
exception
  when no_data_found or too_many_rows then
       return v_age;
end;



---------------



-----------------------
// storedprocedure.html
------------------------

<html>
<head><title>Stored Procedure Call Test </title></head>
<body>
<form name=myform action=/servlet/StoredProcedure method=get>
성명 : <input type=text name=name>
<input type=submit>
</form>
</body>
</html>      


--------------------
StoredProcedure.java
--------------------
/* Oracle의 Stored Procedure를 JDBC로 이용하는 예제입니다.  StoredProcedure.java*/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class StoredProcedure extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {
    Connection con = null;
    Statement stmt = null;    
    
    res.setContentType("text/html; charset=euc-kr");
    PrintWriter out = res.getWriter();  
    try {
      // 오라클 드라이버를 Load 한다
      Class.forName("oracle.jdbc.driver.OracleDriver");

      // 데이타 베이스에 접속을 한다.
      con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:wink", "scott", "tiger");
     
      // Statement object를 생성한다.
  CallableStatement cstmt = con.prepareCall("{? = call employ_age(?) }");

      //Stored Procedure의 input value의 setting및 output value의 type설정
  cstmt.registerOutParameter(1,Types.INTEGER);
  cstmt.setString(2, han(req.getParameter("name")));  //Procedure의 parameter setting
  cstmt.execute();                                    //CallableStatement 실행

  int age = cstmt.getInt(1);

  out.println("요청하신 " + han(req.getParameter("name")) + " 님의 나이는 " + age + " 입니다.");
}


                 catch(ClassNotFoundException e) {  
      out.println("Couldn't load database driver: " + e.getMessage());
    }
    catch(SQLException e) {  
      out.println("SQLException caught: " + e.getMessage());
    }
    finally {      // 언제나 데이타 베이스 연결을 종료한다.
      try {         if (con != null) con.close();  }
catch (SQLException ignored) { }
    }
  }
  //한글변환 함수
  public static String han(String Unicodestr) throws UnsupportedEncodingException {    
      if( Unicodestr == null)    
         return null;    
      return new String(Unicodestr.getBytes("8859_1"),"KSC5601");    
  }   
}

Posted by 양군이당

댓글을 달아 주세요

자바/Web2008. 6. 26. 02:26
원문 http://blog.naver.com/forioso/10009590986

1 문서 개요 #

  • 작성일 : 2006/04/04
  • 작성자 : http://www.0bin.net/moniwiki/wiki.php/Specification/OPML?action=download&value=mail.png
  • 문서 내용 : AJAX XMLHTTPREQUEST에서 데이터 교환 형식으로 사용되는 JSON에 대한 정리

2 개요 #

  • Javascript Object Notation.
  • lightweight data 교환 형식.
  • 사람이 읽고 쓰기 쉬움.
  • 기계가 파싱하고 생성하기 쉬움.

3 형식 #

3.1 Object #

  • 중괄호({})로 시작하고 끝남
  • member : 문자열과 값으로 구성되어 있고 콜론(:)으로 구분, 각 멤버들은 콤마(,)로 구분
  • array : 대괄호([])로 시작하고 끝나며 각 값은 콤마(,)로 구분
  • value : 값은 string, number, object, array, true, false, null 사용 가능
  • string : 문자열은 쌍따옴표(")로 둘러 쌓여야 하며 Unicode character 또는 일반적인 escape 문자(\", \\, \/, \b, \f, \n, \r, \t, \u four-hex-digits)를 포함한다.
    oav.gif
    sn.gif

3.2 예시 #

{

"Image": {

"Width":800,

"Height":600,

"Title":"View from 15th Floor",

"Thumbnail":{

"Url":"http:/\/scd.mm-b1.yimg.com\/image\/481989943",

"Height": 125,

"Width": "100"

},

"IDs":[ 116, 943, 234, 38793 ]

}

}
  • 출처 : Yahoo JSON 예제
  • 예제에서 Image는 최상위 object이고 모든 다른 데이터들은 이 object의 멤버.
  • Width, Height, Title는 숫자와 문자열 데이타를 포함하고 있는 기본적인 멤버.
  • Thumbnail은 Url, Height, Width를 멤버로 포함하고 있는 중첩 object.
  • ?IDs는 숫자 값을 가지고 있는 array.
  • Url 문자열 값에서 슬래쉬(/)가 escape 됨에 주의

4 참고 사이트 #

'자바 > Web' 카테고리의 다른 글

드디어 JavaFX 1.0 정식 Release...  (0) 2008.12.09
Eclipse Ganymede 출동~  (0) 2008.07.02
JSON  (0) 2008.06.26
JSON vs XML  (0) 2008.06.26
XML과 JSON 사이에 변환 패턴  (0) 2008.06.26
JavaScript 객체 JSON  (0) 2008.06.26
Posted by 양군이당
TAG JSON

댓글을 달아 주세요

자바/Web2008. 6. 26. 02:25
* JSON(http://www.crockford.com/JSON/)은 자바스크립트 객체 표기(literal object notation
of JavaScript)를 따르는 가벼운 데이터 교환포맷이다.
(JavaScript Object Notation (JSON) is a lightweight data inerchange format )

* Rule: "Use XML to exchange structured document, use JSON to exchange data."

* JSON을 어디에 써먹을까?
Ajax 기반 프로그래밍시 응답 xml을 핸들링해야 하는데, DOM 트리를 통해 데이터에 접근하는 것보다 동일한 구조를 갖는 javascript 객체로써 다루는 것이 훨씬 편하다.(어떤 언어를 사용하더라도
DOM을 직접 다루는 것은 고통스럽다.)

예를 들어 아래와 같은 xml포맷 데이터를 XMLHTTPRequest를 통해 받았다고 하자.
(xmlhttp.responseXML => 브라우저 내장 파서에 의해 자동파싱된 js DOM 트리 반환)

<response>
  <method>checkName</method>
  <result>yes</result>
</response>

여기서 method 엘리먼트의 값을 뽑으려면 이런식의 코딩이 필요하다. 지랄맞다.

var response = xmlhttp.responseXML.documentElement
alert("메소드명 : " + response.getElementsByTagName('method')[0].firstChild.data);

그럼 동일한 구조의 데이터를 아래처럼 JSON 포맷으로 받았다고 하자.
(xmlhttp.responseText => 응답 text를 그대로 반환)

{"response": {
     "method": "checkName",
     "result": "yes"
 }};

이제 method의 값을 뽑아보자. 해피하다.

var jsonObj = eval('return ' + xmlhttp.responseText);
alert("메소드명 : " + jsonObj.response.method);

즉, ajax를 이용하는 경우 서버단에서 XML 포맷으로 보내지 말고 JSON 포맷으로 보내면
자바스크립트에서 데이터를 쉽게 액세스할 수가 있다는 얘기다.
(Ajax with JSON instead of XML)

출처 : http://blog.naver.com/ecogeo/100012393620

'자바 > Web' 카테고리의 다른 글

Eclipse Ganymede 출동~  (0) 2008.07.02
JSON  (0) 2008.06.26
JSON vs XML  (0) 2008.06.26
XML과 JSON 사이에 변환 패턴  (0) 2008.06.26
JavaScript 객체 JSON  (0) 2008.06.26
Java 객체를 이용해서 JSON객체를 위한 텍스트 생성하기  (0) 2008.06.26
Posted by 양군이당

댓글을 달아 주세요

자바/Web2008. 6. 26. 02:21
출처 정원희's blog, season 2006 start! | 딱따구리
원문 http://blog.naver.com/nobodyuknow/100028605773


Pattern XML JSON Access
1
"e": null o.e
2text "e": "text" o.e
3
"e":{"@name": "value"} o.e["@name"]
4text "e": { "@name": "value", "#text": "text" } o.e["@name"] o.e["#text"]
5text text "e": { "a": "text", "b": "text" } o.e.a o.e.b
6text text "e": { "a": ["text", "text"] } o.e.a[0] o.e.a[1]
7text text "e": { "#text": "text", "a": "text" } o.e["#text"] o.e.a

출처 Night Sidunge | 시둥이
원문 http://blog.naver.com/way133/60029787010

출처 : http://cafe.naver.com/webagencyalone.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=25

xml -> json


1. [패턴1]

<?xml version="1.0"  encoding="Shift_JIS" ?>

  <rss>

    <channel>

      <title>111</title>
      <link>222</link>

    </channel>

  </rss>


  json으로 바꾸면...


{


   rss: {
   

     channel: {


        title: "111",
      link: "222"


     }


   }

}


javascript에서 json변수의 요소를 가저올때(json변수명이 data일 경우)

data.rss.channel.title    ---->111  다음과 같이 써도 동일 data["rss"]["channel"]["title"]

data.rss.channel.link    ---->222  다음과 같이 써도 동일 data["rss"]["channel"]["link"]


2.[패턴2]

<?xml version="1.0"  encoding="Shift_JIS" ?>

  <rss>

    <channel>

      <title>111</title>

      <title>222</title>
      <link>333</link>

    </channel>

    <channel>

      <title>444</title>

      <title>555</title>
      <link>666</link>

    </channel>

  </rss>


json으로 바꾸면...


{


  rss: {


    channel: [
{
       


      title: [
          "111",
          "222"
        ],



      link: "333"
     

    },


    {

  
   title: [
          "444",
          "555"
        ],




      link: "666"
      }]



  }

}


data.rss.channel[0].title[0]     --->111  다음과 같이 써도 동일 data["rss"]["channel"][0]["title"][0]

data.rss.channel[1].link         --->666  다음과 같이 써도 동일 data["rss"]["channel"][1]["link"]


3.패턴[3]

<?xml version="1.0"  encoding="Shift_JIS" ?>

  <rss version="2.0">

    <channel>

      <title>111</title>
      <link opt1="opt1111" opt2="opt222">222</link>

    </channel>

  </rss>


json으로 바꾸면...


{
 

  rss: {


    version: "2.0",

    channel: {


      title: "111",

      link: {


        opt1: "opt1111",
        opt2: "opt222",
        "#text": "222"


      }


     }

  }

}


data["rss"]["channel"]["link"]["#text"]   --->222

data.rss.channel.link.#text 로 하면...에러발생...

#가 파싱할때 예약어인거 같음..


4.패턴4

<?xml version="1.0"  encoding="Shift_JIS" ?>
  <rss version="2.0">
    <channel>
      <title aaa="111"/>
      <asdfsdf/>
    </channel>
</rss>


json으로 바꾸면...


{
  rss: {


     version: "2.0",


     channel: {
      title: { aaa: "111" }


     }


   }


 }



5.아래와같이 동일한 옵션명이 있으면 에러

<bb aa="11" aa="22"/>

옵션명에 :를 넣는경우는 xmlns로 정의된경우만 가능...이외에는 에러남...

아래와 같은 경우 옵션명에 :를 넣음

<?xml version="1.0"  encoding="utf-8" ?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Center"/>
   <Borders/>
   <Font ss:FontName="MS Pゴシック" x:CharSet="128" x:Family="Modern" ss:Size="11"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
</Workbook>

'자바 > Web' 카테고리의 다른 글

JSON  (0) 2008.06.26
JSON vs XML  (0) 2008.06.26
XML과 JSON 사이에 변환 패턴  (0) 2008.06.26
JavaScript 객체 JSON  (0) 2008.06.26
Java 객체를 이용해서 JSON객체를 위한 텍스트 생성하기  (0) 2008.06.26
Tomcat 5.X 버전에서 한글 파라메터 쓰기  (0) 2008.06.26
Posted by 양군이당
TAG JSON, XML, 변환

댓글을 달아 주세요

자바/Web2008. 6. 26. 02:20
출처 ace7min님의 블로그 | ace7min
원문 http://blog.naver.com/ace7min/28724114

클래스이름 = function(파라미터) {

    this.id = 파라미터;

    this.name = 파라미터;

}


Member = function( id, name ) {

    this.id = id;

    this.name = name;

}


var mem = new Member( 'testId', '창마이')


클래스이름.prototype.함수이름 = function( newId, newName ) {

    this.id = newId;

    this.name = newName;

}


Member.prototype.toString = function() {

    return this.id + "[" + this.name + "]";

}


이방법 이외에 Object() 를 이용한 방법으로


var mem = new Object();

mem.id = 'testId';

mem.name = '창마이';

mem.securityNo = '7700001000000';


mem.toString = function() {

    return this.name + "[" + this.id + "]";

}

 

alert( mem.toString() );


JSON 표기법


{ 이름1: 값1, 이름2: 값2, 이름3: 값3 }


var countries = {ko: '대한민국', fr: '프랑스', uk: '영국'};

var koName = countries.ko;

var frName = countries['fr'];


배열형식


[값0, 값1, 값2, 값3]


var countryCodes = ['ko', 'fr', 'uk', 'us'];

var idx0 = countryCodes[0]; //'ko'

var idx1 = countryCodes[2]; //'uk'


배열과 응용


var member = {

    name: '창마이',

    favorateColors: ['파랑', '노랑', '빨강']

};


var message = member.name + "님이 좋아하는 색상은 " +

     member.favorateColors.length + "개이고,";

message += "그중 첫 번째 색상은 " +

     member.favorateColors[0] + "입니다.";



JSON 표기법을 사용한 클래스 정의

 

클래스이름  = function( 파라미터 ) {

    ...

}


클래스이름.prototype = {

    함수명1: function( 파라미터 ) {

        ....

    },

    함수명1: function( 파라미터 ) {

        ....

    }

}


Ex)


Member = function(name, id, securityNo) {
 this.name = name;
 this.id = id;
 this.securityNo = securityNo;
}


Member.prototype = {
 setValue: function(newName, newId, newSecurityNo) {
  this.name = newName;
  this.id = newId;
  this.securityNo = newSecurityNo;
 },
 getAge: function() {
  var birthYear = parseInt(this.securityNo.substring(0, 2));
  var code = this.securityNo.substring(6,7);
  if (code == '1' || code == '2') {
   birthYear += 1900;
  } else if (code == '3' || code == '4') {
   birthYear += 2000;
  }
  var today = new Date();
  return today.getFullYear() - birthYear;
 },
 toString: function() {
  return this.name + "[" + this.id + "]";
 }
}




자바스크립트에서 패키지 정의하기


var ajax = new Object();

ajax.Request = function() {

    ...

}


ajax.Request.prototype = {

    someFunction = function() {

        ...

    },

    ...

}


위에 정의한 클래스 사용하기


var req = new ajax.Request();

req.someFunction();


중첩해서 패키지 만들기

 

var ajax = new Object();

ajax.xhr = new Object();

ajax.xhr.Request = function() {

    ...

}


// 아래와 같이 사용

var req = new ajax.xhr.Request();


빈 클래스 만들기


var ajax = {};

ajax.xhr = {};

ajax.xhr.Request = function() {

    ...

}


JSON 표기법에 대한 정보는 http://www.json.org/ 사이트에서 참고할 수 있다.

'자바 > Web' 카테고리의 다른 글

JSON  (0) 2008.06.26
JSON vs XML  (0) 2008.06.26
XML과 JSON 사이에 변환 패턴  (0) 2008.06.26
JavaScript 객체 JSON  (0) 2008.06.26
Java 객체를 이용해서 JSON객체를 위한 텍스트 생성하기  (0) 2008.06.26
Tomcat 5.X 버전에서 한글 파라메터 쓰기  (0) 2008.06.26
Posted by 양군이당
TAG java, JSON

댓글을 달아 주세요

자바/Web2008. 6. 26. 02:19

복사 http://blog.naver.com/eclips32/30020578345

Simple Java toolkit for JSON (JSON.simple)
==========================================

http://www.JSON.org/java/json_simple.zip

1.Why the Simple Java toolkit (also named as JSON.simple) for JSON?

  When I use JSON as the data exchange format between the AJAX client and JSP
  for the first time, what worry me mostly is how to encode Java strings and
  numbers correctly in the server side so the AJAX client will receive a well
  formed JSON data. When I looked into the 'JSON in Java' directory in JSON
  website,I found that wrappers to JSONObject and JSONArray can be simpler,
  due to the simplicity of JSON itself. So I wrote the JSON.simple package.

2.Is it simple,really?

  I think so. Take an example:

  import org.json.simple.JSONObject;

  JSONObject obj=new JSONObject();
  obj.put("name","foo");
  obj.put("num",new Integer(100));
  obj.put("balance",new Double(1000.21));
  obj.put("is_vip",new Boolean(true));
  obj.put("nickname",null);
  System.out.print(obj);

  Result:
  {"nickname":null,"num":100,"balance":1000.21,"is_vip":true,"name":"foo"}

  The JSONObject.toString() will escape controls and specials correctly.

3.How to use JSON.simple in JSP?

  Take an example in JSP:

  <%@page contentType="text/html; charset=UTF-8"%>
  <%@page import="org.json.simple.JSONObject"%>
  <%
    JSONObject obj=new JSONObject();
    obj.put("name","foo");
    obj.put("num",new Integer(100));
    obj.put("balance",new Double(1000.21));
    obj.put("is_vip",new Boolean(true));
    obj.put("nickname",null);
    out.print(obj);
    out.flush();
  %>

  So the AJAX client will get the responseText.

4.Some details about JSONObject?

  JSONObject inherits java.util.HashMap,so it don't have to worry about the
  mapping things between keys and values. Feel free to use the Map methods
  like get(), put(), and remove() and others. JSONObject.toString() will
  combine key value pairs to get the JSON data string. Values will be escaped
  into JSON quote string format if it's an instance of java.lang.String. Other
  type of instance like java.lang.Number,java.lang.Boolean,null,JSONObject and
  JSONArray will NOT escape, just take their java.lang.String.valueOf() result.
  null value will be the JSON 'null' in the result.

  It's still correct if you put an instance of JSONObject or JSONArray into an
  instance of JSONObject or JSONArray. Take the example about:

  JSONObject obj2=new JSONObject();
  obj2.put("phone","123456");
  obj2.put("zip","7890");
  obj.put("contact",obj2);
  System.out.print(obj);

  Result:
  {"nickname":null,"num":100,"contact":{"phone":"123456","zip":"7890"},"balance":1000.21,"is_vip":true,"name":"foo"}

  The method JSONObject.escape() is used to escape Java string into JSON quote
  string. Controls and specials will be escaped correctly into \b,\f,\r,\n,\t,
  \",\\,\/,\uhhhh.

5.Some detail about JSONArray?

  org.json.simple.JSONArray inherits java.util.ArrayList. Feel free to use the
  List methods like get(),add(),remove(),iterator() and so on. The rules of
  JSONArray.toString() is similar to JSONObject.toString(). Here's the example:

  import org.json.simple.JSONArray;

  JSONArray array=new JSONArray();
  array.add("hello");
  array.add(new Integer(123));
  array.add(new Boolean(false));
  array.add(null);
  array.add(new Double(123.45));
  array.add(obj2);//see above
  System.out.print(array);

  Result:
  ["hello",123,false,null,123.45,{"phone":"123456","zip":"7890"}]

6.What is JSONValue for?

  org.json.simple.JSONValue is use to parse JSON data into Java Object.
  In JSON, the topmost entity is JSON value, not the JSON object. But
  it's not necessary to wrap JSON string,boolean,number and null again,
  for the Java has already had the according classes: java.lang.String,
  java.lang.Boolean,java.lang.Number and null. The mapping is:

  JSON          Java
  ------------------------------------------------
  string      <=>   java.lang.String
  number      <=>   java.lang.Number
  true|false  <=>   java.lang.Boolean
  null        <=>   null
  array       <=>   org.json.simple.JSONArray
  object      <=>       org.json.simple.JSONObject
  ------------------------------------------------

  JSONValue has only one kind of method, JSONValue.parse(), which receives
  a java.io.Reader or java.lang.String. Return type of JSONValue.parse()
  is according to the mapping above. If the input is incorrect in syntax or
  there's exceptions during the parsing, I choose to return null, ignoring
  the exception: I have no idea if it's a serious implementaion, but I think
  it's convenient to the user.

  Here's the example:

  String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
  Object obj=JSONValue.parse(s);
  JSONArray array=(JSONArray)obj;
  System.out.println(array.get(1));
  JSONObject obj2=(JSONObject)array.get(1);
  System.out.println(obj2.get("1"));

  Result:
  {"1":{"2":{"3":{"4":[5,{"6":7}]}}}}
  {"2":{"3":{"4":[5,{"6":7}]}}}

7.About the author.

  I'm a Java EE developer on Linux.
  I'm working on web systems and information retrieval systems.
  I also develop 3D games and Flash games.

  You can contact me through:
  Fang Yidong<fangyidong@yahoo.com.cn>
  Fang Yidong<fangyidng@gmail.com>

  http://www.JSON.org/java/json_simple.zip

'자바 > Web' 카테고리의 다른 글

JSON  (0) 2008.06.26
JSON vs XML  (0) 2008.06.26
XML과 JSON 사이에 변환 패턴  (0) 2008.06.26
JavaScript 객체 JSON  (0) 2008.06.26
Java 객체를 이용해서 JSON객체를 위한 텍스트 생성하기  (0) 2008.06.26
Tomcat 5.X 버전에서 한글 파라메터 쓰기  (0) 2008.06.26
Posted by 양군이당
TAG java, JSON

댓글을 달아 주세요