Curl Javassm Format method for passing in a JSON array

Source: Internet
Author: User

Curl and Java combine incoming Get.post,head requests,

For example: Curl's address:

Curl-l 127.0.0.1:8080/spacobj/core/do?acid=100-h "token:101hh"-H "Content-type:application/json"-X post-d {"TelNum" : "13521389587", "Pass": "' my12345 '", "Nick": "Tomorrow will be Better", "SMS": "' 7864AQ '"}

Note that the string in the JSON format must be "' inside is a string '"

The code obtained in Java is as follows:

@RequestMapping (value = "Do", method = Requestmethod.post)
Public String Mydo (
@RequestParam (value = "Acid", required = false, DefaultValue = "0") int acid,
@RequestHeader (value = "token", required = false, DefaultValue = "0") String token,
HttpServletRequest request, HttpServletResponse response)
Throws Unsupportedencodingexception, IOException, parseexception {

The following creates an object that accepts the data that the JSON passes over

T_account TAC = new T_account ();
StringBuilder sb = new StringBuilder ();
BufferedReader in = new BufferedReader (New InputStreamReader (
Request.getinputstream (), "UTF-8"));
String line = null;
while (line = In.readline ()) = null) {
Sb.append (line);

String json = sb.tostring ();
Jsonobject Jsonobject = Jsonobject.fromobject (JSON);

Iterator ite = Jsonobject.keys ();

Iterate over the Jsonobject data and receive it with the object. By key, it is the field of the object that accepts the JSON request from post.

while (Ite.hasnext ()) {
String key = Ite.next (). toString ();

if (Key.equals ("Telnum")) {
Tac.settelnum (Jsonobject.get (key). ToString ());
}
if (Key.equals ("pass")) {
Tac.setpass (Jsonobject.get (key). ToString ());
}
if (Key.equals ("Nick")) {
Tac.setnick (Jsonobject.get (key). ToString ());
}
if (key.equals ("SMS")) {
Tac.setsms (Jsonobject.get (key). ToString ());
}

String value = Jsonobject.get (key). ToString ();

}

}

Curl Javassm Format method for passing in a JSON array

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.