JSON

jsonѧϰÕûÀí(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-09-20 18:00 ÎÒÒªÆÀÂÛ( )

String s = "{'shopList':[{name:'ÖØÁ¿',property:'p1'},{name:'³ß´ç',property:'p2'},{name:'ÏÔ¿¨ÀàÐÍ',property:'p3'},{name:'Ó²ÅÌÈÝÁ¿',property:'p4'},{name:'´¦ÀíÆ÷',property:'p5'},{name:'ÄÚ´æ',property:'p

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 ±äÁ¿£¬¾Í¿ÉÒÔÁ¢¿ÌʹÓøñäÁ¿²¢¸üÐÂÒ³ÃæÖеÄÐÅÏ¢ÁË¡£

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • C#½«Json½âÎö³ÉDateTableµÄ·½·¨

    C#½«Json½âÎö³ÉDateTableµÄ·½·¨

    2016-09-21 11:00

  • phpÅжÏjson¸ñʽÊÇ·ñÕýÈ·ºÍÊÇ·ñΪjson¸ñʽµÄ·½·¨

    phpÅжÏjson¸ñʽÊÇ·ñÕýÈ·ºÍÊÇ·ñΪjson¸ñʽµÄ·½·¨

    2016-09-19 16:01

  • iOS ÍøÂç±à³Ì £¨ËÄ£©JSON½âÎö

    iOS ÍøÂç±à³Ì £¨ËÄ£©JSON½âÎö

    2016-09-19 10:00

  • Androidѧϰ±Ê¼Ç45Ö®gson½âÎöjson

    Androidѧϰ±Ê¼Ç45Ö®gson½âÎöjson

    2016-09-18 18:01

ÍøÓѵãÆÀ
µ