Home > Web Front-end > JS Tutorial > body text

js creates jsonArray and transmits it to the background and comprehensive analysis in the background_Basic knowledge

WBOY
Release: 2016-05-16 15:06:02
Original
1890 people have browsed it

I never figured out the difference between jsonArray and jsonObject before, but I finally figured it out today.

jsonArray is an array, containing data with [ ], and jsonObject is an object, containing data with { }.

Introducing an easy way to build a jsonArray in the frontend

 var array=[];

 for(int i=0;i<10;i++){

  var item={};

  item.a="a"+i;

  item.b="b"+i;

  array.push(item);

 }

 Ajax:

 params:{

 data:JSON.stringify(array),

 type:1

 }
Copy after login

Can receive in the background:

  String data=request.getParameter("array");

  JSONArray myArray=JSONArray.fromObject(data);

  for(int i=0;i<myArray.size();i++){

   JSONObject object=myArray.getJSONObject(i);

   String a = object.getString('a');

   String b = object.getString('b');

  }
Copy after login

The above article about js creating jsonArray, transmitting it to the background and comprehensive analysis of the background is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support Script Home.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!