Web background and phone interactive data format problems

Source: Internet
Author: User

recently, the requirement of data interaction between systems has been realized by Http+post method.the usual way isApplication/json Mode direct post JSON objectas
 
   
  
  1. {"siteId":"ZHAN20160329TDLXJND144649","apiSecret":"userid123","workNumber":"FJ-8006-160912-1715-00001","fluetype":"2","apiKey":"yyxt"}
backstage can directly SPRINGMVC directly receive and turn to the related Vo object processing.
in a scenario where the phone interacts with the background, a format requirement is encountered
 
   
  
  1. 方法名称:appScanBuildingData
  2. 请求:json字符串形式,最外层用data包裹
The demo format example is
 
   
  
  1. data={"alarmDetail":[{"address":"中国","cgi":"CGI0"},{"address":"米国","cgi":"CGI1"},{"address":"日本","cgi":"CGI2"}],"areaCode":"350723","cellNumber":"1599999","cityCode":"350723","lat":"232.545","lon":"98.233","workNO":"ZB33000333337"}
How does this data need to be generated?
The following instructions refer primarily to https://imququ.com/post/four-ways-to-post-data-in-http.html
The format requirements of this wonderful flower are actually usedContent-type: should be for application/x-www-form-urlencoded;the submitted data is encoded in the key1=val1&key2=val2 manner, and both key and Val are URL-transcoded.
 
   
  
  1. POST http://www.example.com HTTP/1.1
  2. Content-Type: application/x-www-form-urlencoded;charset=utf-8
  3. title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3

when transmitting data in Application/json Content-type, the transmitted object simply needs to be serialized by JSON. When the data is transmitted in a application/x-www-form-urlencoded manner. the requested content needs to be: =.. &, .... =.. Format, the content in the request body will be automatically split with "&" and "=".

application/x-www-form-urlencoded mode transmission, background receive time can use
String data = Request.getparameter ("Data");This is the way to accept data in JSON format. Then use the object as:Alarminfo vo=NULL;Vo=jsonobject. parseobject (Data, Alarminfo. class);
The original intention of this format is to consider the background to receive data conveniently.





From for notes (Wiz)

Web background and phone interactive data format problems

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.