String s = "{'shopList':[{name:'ÖØÁ¿',property:'p1'},{name:'³ß´ç',property:'p2'},{name:'ÏÔ¿¨ÀàÐÍ',property:'p3'},{name:'Ó²ÅÌÈÝÁ¿',property:'p4'},{name:'´¦ÀíÆ÷',property:'p5'},{name:'ÄÚ´æ',property:'p6'},{name:'ÐͺÅ',property:'p7'},{name:'»õºÅ',property:'p8'},{name:'Æ·ÅÆ',property:'p9'}]}";
//´´½¨MAP
Map<String, Object> map = new HashMap<String, Object>();
map.put("shopList", Shop.class);
//JSONObject.toBean()·½·¨µÄÈý¸ö²ÎÊý·Ö±ð±íʾÊý¾ÝÔ´¶ÔÓ¦µÄJSON¶ÔÏó£¬×ª»¯ºóµÄ¶ÔÏóShopListºÍÊý¾ÝÔ´map
ShopList shopList = (ShopList) JSONObject.toBean(JSONObject.fromObject(s)
, ShopList.class, map);
//±éÀúshopList
for (Iterator<Shop> i = (Iterator<Shop>) shopList.getShopList().iterator(); i.hasNext();) {
Shop shop = i.next();
System.out.println(shop.getProperty() + "->" + shop.getName());
}
½á¹û£ºp1->ÖØÁ¿
p2->³ß´ç
p3->ÏÔ¿¨ÀàÐÍ
p4->Ó²ÅÌÈÝÁ¿
.
JsonÓëXMLµÄת»»
String s = "{name:'ÖØÁ¿',property:'p1'}";
JSONObject object = JSONObject.fromObject(s);
XMLSerializer serializer = new XMLSerializer();
String xmlObject = serializer.write(object);
System.out.print(xmlObject);
½á¹û£º
<?xml version="1.0" encoding="UTF-8"?>
<o>
<nametype="string">ÖØÁ¿</name>
<property type="string">p1</property>
</o>
JAVASCRIPT¼òµ¥µÄ´¦ÀíJSONÊý¾Ý£º
Ö÷ÒªÎÊÌ⣺ÈçºÎÔÚ·þÎñÆ÷¶ËÉú³É JSON ¸ñʽµÄÊý¾ÝÒԱ㷢Ë͵½¿Í»§¶Ë£¬ÒÔ¼°¿Í»§¶ËÈçºÎʹÓà JavaScript ´¦Àí JSON ¸ñʽµÄÊý¾Ý¡£
1£ºÔÚ¿Í»§µ¥´¦ÀíJSONÊý¾Ý
×öÒ»¸ö¼òµ¥µÄJSON¶ÔÏó£¬Ê¹ÓÃJAVASCRIPT½øÐнâÎö¡£
function handleJson() {
var j={"name":"Michael","address":
{"city":"Beijing","street":"ChaoyangRoad","postcode":100025}
};
document.write(j.name);
document.write(j.address.city);
}
¼ÙÈç´Ó·þÎñÆ÷´²¸ø¿Í»§¶ËµÄJSONΪ£º
{"name":"Michael","address":
{"city":"Beijing","street":"ChaoyangRoad","postcode":100025}
};
ÄÇôµÃ³ö£º
½«Æ丳ֵ¸øÒ»¸ö JavaScript ±äÁ¿£¬¾Í¿ÉÒÔÁ¢¿ÌʹÓøñäÁ¿²¢¸üÐÂÒ³ÃæÖеÄÐÅÏ¢ÁË¡£
¡¡