Java and Json__js

Source: Internet
Author: User

Spell out a simple JSON,

The effect is probably:

{"Data": List}, there are two elements in the list, also JSON format

The code is:

public static void Main (string[] args) {
Jsonobject all=new jsonobject ();//FINAL JSON
Jsonarray array=new Jsonarray ();//json list
Jsonobject data=new jsonobject ();//json list Element
Hashmap<string,object> list=new hashmap<string,object> ()//batch assignment to data
List.put ("T1", "ttt111");
List.put ("T2", "ttt222");
Data.putall (list);
Array.add (data);
Hashmap<string,object> list2=new hashmap<string,object> ();
List2.put ("T1", "ttt333");
List2.put ("T2", "ttt444");
Data.putall (LIST2);
Array.add (data);
All.put ("Data", array);
try {
String Result=json.json (All);
SYSTEM.OUT.PRINTLN (result);
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

The result of the output is:

{"Data": [{"T2": "ttt444", "T1": "ttt333"},{"T2": "ttt444", "T1": "ttt333"}]}

Among them, Jsonobject is Com.alibaba.dubbo.common.json.jsonobject,jsonarray is Com.alibaba.dubbo.common.json.JSONArray

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.