SPRINGMVC Learning Note 001-server-side get JSON string and parse

Source: Internet
Author: User
Tags browser cache

First, the server side gets the JSON string and resolves

Way One:

The front end sends a getjsonstring.spring request, which is added in time to ensure that the browser takes it as a different request each time, without invoking the browser cache.

Idea: Use Json.stringify () to convert a JS object instance [Object:object] into a JSON-formatted string. $.post () The optional parameters accepted by data can be plainobject/string

A key-value pair or string that is key/value.

    

<script src= "Jquery-1.3.2.js" ></script> <script src= "Json2.js" ></script> <script& Gtfunctionuserinfo (username, password) { This. Username =username;  This. Password =password; }            functionSendajax () {varUserinforef =NewUserInfo (' Gaohong ', ' 123 '); varJsonstringref =json.stringify (USERINFOREF); $.post ("Getjsonstring.spring?t=" +NewDate (). GetTime (), {jsonstring:jsonstringref}); }        </script>

Backend code: Idea: The Jsonobject.fromobject () method converts a JSON-formatted string into a Jsonobject-Java object.

Note: The request sent by Ajax does not add the path to the current directory, and the request sent by the form submits the directory path to the file where the request was sent.

Jsonobject.fromobject () is a JSON parsing method provided by Json-lib-2.3-jdk1.5.jar.

    

@RequestMapping (value = "getjsonstring") public string getjsonstring (@RequestParam ("jsonstring") string jsonstring) { Jsonobject object = Jsonobject.fromobject (jsonstring); System.out.println (Object.get ("username")); System.out.println (Object.get ("password")); return "test.jsp";}

  

Method Two: The technique of automatically turning from a JSON-formatted string to an entity using SPRINGMVC.

SPRINGMVC Learning Note 001-server-side get JSON string and parse

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.