JSON JavaÓëAJAX(Jquery)
Ò»¡¢JSON ÊÇʲô£¿
JSON µÄÈ«³ÆÊÇJavaScript Object Notation£¬ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ¡£
JSON ÓëXML ¾ßÓÐÏàͬµÄÌØÐÔ£¬ÀýÈçÒ×ÓÚÈ˱àдºÍÔĶÁ£¬Ò×ÓÚ»úÆ÷Éú³ÉºÍ½âÎö¡£µ«ÊÇJSON ±È
XML Êý¾Ý´«ÊäµÄÓÐЧÐÔÒª¸ß³öºÜ¶à¡£JSON ÍêÈ«¶ÀÁ¢Óë±à³ÌÓïÑÔ£¬Ê¹ÓÃÎı¾¸ñʽ±£´æ¡£
JSON Êý¾ÝÓÐÁ½Öֽṹ£º
• Name-Value ¶Ô¹¹³ÉµÄ¼¯ºÏ£¬ÀàËÆÓÚJava ÖеÄMap¡£
• Value µÄÓÐÐòÁÐ±í£¬ÀàËÆÓÚJava ÖеÄArray¡£
Ò»¸öJSON ¸ñʽµÄÊý¾ÝʾÀý£º
{
"Name": "Apple",
"Expiry": "2007/10/11 13:54",
"Price": 3.99,
"Sizes": [
"Small",
"Medium",
"Large"
]
}
¸ü¶à¹ØÓÚJSON Êý¾Ý¸ñʽµÄ˵Ã÷²Î¿´JSON ¹Ù·½ÍøÕ¾£ºhttp://www.json.org£¨ÖÐÎÄ
ÄÚÈݲο´£ºhttp://www.json.org/json-zh.html£©
¶þ¡¢Í¨¹ýjavaÀ´´´½¨JSON¶ÔÏó
1.ÒýÈëjar°ü
ÎÒÕâÀïʹÓõÄÊÇjson-lib-2.3-jdk15.jar£¬ÏÂÔصØÖ·£ºhttp://sourceforge.net/projects/json-lib/files/
Json-lib requires (at least) the following dependencies in your classpath:
jakarta commons-lang 2.4
jakarta commons-beanutils 1.7.0
jakarta commons-collections 3.2
jakarta commons-logging 1.1.1
ezmorph 1.0.6
2.ÖØÒªµÄ¶ÔÏó¼°·½·¨
1£©JSONObject£ºJSON¶ÔÏó{}¡£
2£©JSONArray£ºJSONÊý×é¶ÔÏó£¬[{},{}]¡£
3£©fromObject(object)£º½«¶ÔÏóת»»ÎªJSON¶ÔÏó¡£
4£©JSONObject.accumulate(key,value)£ºÏòJSONObjectÖÐÔö¼ÓJSONÊý¾Ý£¬¿ÉÒÔÖظ´¡£
5£©element(key,value)£ºÏòJSON¶ÔÏóÖÐÔö¼ÓJSONÊý¾Ý£¬Èç¹ûÖظ´ºóÒ»¸ö»áÌ滻ǰһ¸ö¡£
6£©toString(i,i)£º½«JSON¶ÔÏóת»»Îª×Ö·û´®£¬Èç¹û°üº¬²ÎÊý£¬Êǽ«ÆäÃÀ»¯ºóÊä³ö¡£
ÒÔÏÂÊÇÒ»¸öservletÊä³öJSONµÄÀý×Ó£º
package com.netqin.function.demo.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import com.netqin.function.demo.model.People;
import com.netqin.function.demo.model.Phone;
public class JsonServlet extends
Ïà¹ØÎĵµ£º
±¾ÎÄ°üÀ¨:
A: servletÔ´ÂëʵÀý
B: servlet²¿Êð
C: ¿Í»§¶ËÔ¶³Ìµ÷ÓÃ
D: servlet¿ª·¢µ÷Óù¤¾ß
A: servletÔ´ÂëʵÀý
package com.viewlinecn.userlogin.www.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http ......
ʵÑé»·¾³£ºJDK1.5¡¢Eclipse3.1¡¢XP²Ù×÷ϵͳ
·Ö´ÊϵͳJava½Ó¿Ú½âѹ°ü£ºd:\fenci£¨http://www.nlp.org.cnÖвéÕÒÏÂÔØ£©
µ¼Èë²½Ö裺
ÔÚEclipseÖÐн¨JavaÏîÄ¿£¬Ãû³ÆΪ£ºWordSpli£¬Ä¿Â¼½á¹¹ÈçÏÂËùʾ£º
ÓÒ»÷WordSplitÏîÄ¿£¬Ñ¡Ôñ“µ¼È딣¬½«µ¯³öµ¼Èë´°¿Ú£¬Ñ¡ÔñÁбíÖеēÎļþϵͳ”£¬µ¯³ö“ÎļþÏµÍ ......
Ô¶³Ìµ÷ÊÔjava web start ÓÃjavawÆô¶¯³ÌÐò¼´¿É£ºÈçÏ "D:\tools\jdk6.0\bin\javaws" -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5016 d:\login.jsp.jnlp È»ºóÔÚeclipseÀïÃæ ½¨Á¢ Ô¶³Ìµ÷ÊÔ Á¬µ½5016¶Ë¿Ú¾Í¿ÉÒÔÁË¡£ jnlpÎļþ ×Ô¼º´Ó·þÎñÆ÷ÉÏÏÂÔØÏÂÀ´¾ÍºÃ¡£ ......
»¨ÁËÒ»¸ö¶àÔÂÓÃJava NIOдÁËÒ»¸ö¶¨ÖƵÄHTTP Server£¬Ö÷ÒªÊÇÖ§³ÖÎÒµÄWeBuzz.IMÍøÒ³°æÁÄÌì·þÎñ
¡£
ÏȽéÉÜÒ»ÏÂWeBuzz.IMÍøÒ³ÁÄÌì·þÎñ¡£
WeBuzz.IM
ÊÇÒ»¿îÍøÒ³°æ¼´Ê±ÁÄÌ칤¾ß£¬ÓÃÓÚ°ïÖúÓû§Í¨¹ýÍøÒ³ºÍÅóÓÑÁÄÌì¡£Gtalk£¨Google Talk£©
¡¢MSN£¨Windows Live Messenger£©
¡¢Yahoo! Messenger£¨Yahoo! Chat£¬ÓÖ³ÆΪÑÅ»¢Í¨£©
......
ÎÒÔÚÒ»¸öÓ¡¶ÈÍâ°ü¹«Ë¾¹¤×÷¡£ÎÒËù×öµÄϵͳ´ó²¿·ÖÊÇÓ¡¶È³ÌÐòԱдµÄ¡£
¿´ÁËËûÃǵĴúÂëÓиöÌصã¸ø´ó¼ÒÆÀÆÀ¡£
1¡¢ËûÃÇдµÄ´úÂë±È½ÏÑϽ÷£¬±ÈÈçÔÚÑ»·Ò»¸ö¼¯ºÏÇ°»á×÷nullÅжϣ¬·½·¨ÀàÃüÃûÒ²±È½Ï¹æ·¶Ò׶®¡£
2¡¢ËûÃÇ£¬×¢ÊÍдµÄ²»¶à£¬µ«logдºÜÇÚ¿ì¡£
3¡¢ËûÃǺÃÏñ²»Ì«Ï²»¶ÓÃÁÙʱ±äÁ¿£¬Äܲ»Óþ¡Á¿²»Óá£
4¡¢ËûÃǵĴúÂëÈçÅжÏÒ»¸öb ......