Java,jquery parsing of JSON

Source: Internet
Author: User

JSON is often used for browser-to-server data transfer, so we often encapsulate and disassemble json in the browser and server segments, so here's a quick introduction to these.

1, the server side, that is, Java, we use Net.sf.json-lib, if it is maven, to add dependencies, with the following:

<!--json-lib-->  <dependency>      <groupId>net.sf.json-lib</groupId>      < artifactid>json-lib</artifactid>      <version>2.4</version>      </dependency >

Pay special attention to the marked red part, must add, otherwise it will be wrong, because JSON has two versions, 13 and 15, where the choice of 15

The JSON is then parsed and encapsulated, with the first parsing

Json->list

Jsonarray Jsonarray = jsonarray.fromobject (jsonarraydata); List<Map<String,Object>> Maplistjson = (list) Jsonarray;

Json->map

Jsonobject jsonobject = jsonobject.fromobject (jsonobjectdata); Map<string, object> Mapjson = Jsonobject.fromobject (Jsonobject);

Json->object

/**@return*/privatestatic  Object Json2simplebean () {    = "{\" age\ ": 23,\" id\ ": 123,\" name\ ": \" Tt_2009\ "," +            "\" province\ ": \" shanghai \ ", \" sex\ ": \" male \ "}";     = Jsonobject.fromobject (jsonstr);     return Jsonobject.tobean (Jsonbean, Simpleuser.  Class);}

Let's talk about wrapping it in a JSON style.

Next is jquery's encapsulation and parsing of JSON

1,str->Json$.parsejson (str); 2,json->strjson.stringify (obj)

Java,jquery parsing of JSON

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.