Home >Web Front-end >JS Tutorial >js creates jsonArray and transmits it to the background and comprehensive analysis in the background_Basic knowledge

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 15:06:021974browse

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

 }

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');

  }

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.

Statement:
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