JSON.simple

2013. 4. 23. 23:45 from script

SIMPLE EXAMPLE

 

 java

 

jsp 




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

[출처] json simple test|작성자 우앙

'script' 카테고리의 다른 글

document.implemention.hasFeature('Core')  (0) 2013.04.19
decodeXSS  (0) 2012.10.04
fileupload  (0) 2012.07.06
정규식 : 특정단어 제외  (0) 2012.03.01
undefined, null, typeof  (0) 2012.01.11
Posted by 에시드 :

document.implemention.hasFeature()

boolean hasFeature(String feature, String version);

전달인자

feature 지원여부를 알아볼 기능 이름

version 지원 여부를 알아볼 기능의 버전 번호. 버전에 상관없이  지원여부만 확인하려면, null 또는 빈문자열("").

           DOM 레벨2명세서에서 지원하는 버전번호는 1.0과 2.0이다.

반환값

DOM 구현에서 특정기능의 특정버전을 완벽히 지원하면 true, 아니면 false를 반환한다.

버전번호를 지정하지 않고, DOM 구현에서 특정기능의 한버전만이라도 완벽히 지원하면 true

 

feature

Core : Node, Element, Document, Text와 그밖의 모든 DOM구현에서 기본적인 역활을 담당하는 인터페이스들을 구현한다.

          표준을 준수하는 모든 구현은 이모듈을 지원해야 한다.

HTML : HTMLElement, HTMLDocument와 그밖의 HTML에 특수한 인터페이스를 구현한다.

XML : Entity, EntityReference, ProcessingInstruction, Notation과 XML 문서에 대해 유용하게 사용할수있는 기타 노드 타입을

        구현한다.

StyleSheets : 스타일시트와 관현해 공통적인 정보를 알려주는 간단한 인터페이스를 구현한다.

CSS : CSS 스타일시트에 특수한 인터페이스를 구현한다.

CSS2 : CSS2Properties 인터페이스를 구현한다.

Events : 기본적인 이벤트 처리 인터페이스를 구현한다.

UIEvents : 사용자인터페이스 관련 이벤트를 처리하는 인터페이스를 구현한다.

MouseEvents : 마우스 이벤트를 처리하는 인터페이스를 구현한다.

HTMLEvents : HTML 이벤트를 처리하는 인터페이스를 구현한다.

MutationEvents : 문서변경 이벤트를 처리하는 인터페이스를 구현한다.

Range : 문서의 특정구역을 조작하는 인터페이스를 구현한다.

Traversal : 향상된 문서 탐색기능을 지원하는 인터페이스를 구현한다.

Views : 문서 뷰를 위한 인터페이스를 구현한다.

 

다음과 같이 사용한다.

 

 


 
 
 

 

'script' 카테고리의 다른 글

JSON.simple  (0) 2013.04.23
decodeXSS  (0) 2012.10.04
fileupload  (0) 2012.07.06
정규식 : 특정단어 제외  (0) 2012.03.01
undefined, null, typeof  (0) 2012.01.11
Posted by 에시드 :

알 수 없는 런타임 오류가 발생할 수 있는 가능성은 무지하게 많지만, IE에서는 발생하고 FireFox에서는 발생하지 않는다면 읽기전용 속성 태그에 ID를 부여하고 innerHTML을 사용했을 가능성이 있다.


** IE에서 COL COLGROUP FRAMESET HTML STYLE TABLE TBODY TFOOT THEAD TITLE TR 개체에서는 읽기전용이고 그 외의 개체에서는 모두 읽기/쓰기이다. 디폴트값은 없다.

 

http://www.nextstep.co.kr/37

'HTML/CSS' 카테고리의 다른 글

CSS display 속성  (0) 2011.12.01
Posted by 에시드 :

이클립스에서 소스를 다 받고 각종 라이브러리 잡아준후

웹로직 서버 플러그인은 설치된 이클립스 유로파라 서버 퍼스첵티브 창에서 WAS서버 추가했고,

add project하여 서버 퍼스펙티브 창에서도 해당 프로젝트 잘 물고 있었는데...

계속된 weblogic.jar 파일이 클래스패스에 안잡혀 나타는 오류작열

 

결국 WEB-INF 하위 lib에 weblogic.jar를 넣는 상황까지 ;;;

알고 보니 Project Facets에 서버 런타임 활성 비활성 하는 메뉴있음

 

 

이클립스 상에서 서버 런타임 추가 방법

프로젝트 프로퍼티

project Facets

modify project

show runtimes

체크 BEA Weblogic Server v8.1

 

 

 

'WAS' 카테고리의 다른 글

iplanet + weblogic  (0) 2012.10.09
Posted by 에시드 :

JSP 2.0 과 Servlet 2.4 는 weblogic 9.0 부터 지원된다.

weblogic 8.1은 jsp 1.1과 1.2, servlet 2.2와 2.3을 지원한다.

 

Standard Tag library 1.0 / Struts 1.2.x는 java Servlet 2.3 and javaServerPage 1.2를 지원하고 (tomcat 4.1.x 버젼)

Standard Tag library 1.1 / Struts 1.3.x는 java Servlet 2.4 and javaServerPage 2.0를 지원한다 (tomcat 5.x.x 버젼)

'EJB' 카테고리의 다른 글

weblogic Admin의 사용자, 암호 분실시  (0) 2013.04.08
웹로직 컨텍스트 관련  (0) 2013.04.08
Posted by 에시드 :