Jsonarray Turn Jsonobject

Source: Internet
Author: User

I have not known the difference between Jsonarray and Jsonobject, and today I finally figured it out.

Jsonarray is an array that contains data with [], Jsonobject is an object, and {} contains data.

Introduce an easy way to build a jsonarray in the foreground

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}

In the background you can receive:

  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 JS created Jsonarray transmission to the background and the background of a comprehensive analysis is a small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we support the script home.

Jsonarray Turn Jsonobject

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.