アプリのパラメータの受け渡し:
{ "デバイスID": "123" 、 "labDatas" :[{ "epcId": "E20000198707014902107B3A" 、 "時間": "7" }、{ "epcId": "E20000198707015202107B00" 、 "時間": "2" }、 { "epcId": "E20000198707015002107AFF" 、 "時間": "3" }、{ "epcId": "E20000198707016502108CBA" 、 "時間": "1" }、{ "epcId": "E20000198707015102107B3B" 、 "時間": "3" }、{ "epcId": "E200001987070160021083C0" 、 "時間": "1" }、{ "epcId": "E200001987070156021083BE" 、 "時間": "2" }、{ "epcId": "E200001987070161021083FC" 、 "時間": "3" }、{ "epcId": "E20000198707016402108C7E" 、 "時間":「2 " }、{ "epcId": "E20000198707016202108C7D" 、 "時間": "1" }、{ "epcId": "E200001987070159021083FB" 、 "時間": "1" }、{ "epcId": "E200001987070157021083FA" 、 "回": "1" }、{ "epcId": "E200001987070158021083BF" 、 "時間": "3" }、{ "epcId": "E20000198707016802108C80" 、 "時間": "1" }、{ "epcId": "E20000198707016902108CBC" 、 "時間": "1" }]、 "タイプ": "检查" }
背景レセプション:
この方法の一つ:
@RequestMapping(値= "アップ" ) @ResponseBody 公共 JSONObjectアップデータ(HttpServletRequestのリクエスト、HttpServletResponseの応答)がスローにUnsupportedEncodingException { request.setCharacterEncoding( "UTF-8" )。 response.setCharacterEncoding( "UTF-8" )。 response.setContentType( "アプリケーション/ JSON" )。 しようと{ のStringBuffer JSON = 新しいStringBufferを(); BufferedReaderのリーダー = request.getReader()。 文字列の行 = nullを。 一方、((ライン= reader.readLine())!= NULL ){ json.append(ライン) } のSystem.out.println( "接收到的JSON数据为----------------->" + json.toString())。 } キャッチ(例外e){ e.printStackTrace(); } を返す( ""、Constants.STATUS_SUCCESS、 "成功"をassemblyJson )。 }
方法2:
@RequestMapping(値= "アップ" ) @ResponseBody 公共 JSONObjectアップデータ(@RequestParam地図の<string、オブジェクト> 体){ System.out.printlnは(本体) 返す( ""、Constants.STATUS_SUCCESS、 "成功" assemblyJsonを)。 }
要約:
要求オブジェクトは、JSON遠位バックエンド@RequestParamを渡され、
文字列オブジェクトのJSON遠位後部@RequestBodyを使用するための要求を渡します。