Java and JSON

Source: Internet
Author: User

 

Public static void main (string [] ARGs ){
String jsonstring = "[{\" ID \ ": \" 1 \ ", \" fields \ ": [{\" Name \ ": \" Age \", \ "value \": 10 },{ \ "Name \": \ "ID \", \ "value \": \ "1 \"}, {\ "Name \": \ "Name \", \ "value \": \ "name-1 \"}] },{ \ "ID \": \ "2 \", \ "fields \": [{\ "Name \": \ "Age \", \ "value \": 10 }, {\ "Name \": \ "ID \", \ "value \":
\ "2 \" },{ \ "Name \": \ "Name \", \ "value \": \ "name-2 \"}] ";
Jsonarray ja = jsonarray. fromobject (jsonstring );
Jsonobject JB = (jsonobject) Ja. Get (0 );
System. Out. println (JB. getstring ("fields "));


// Use a map as an Example
Map <string, string> map = new hashmap <string, string> ();
 
// Add a data record for the map and upload the loginname on the page
Map. Put ("name", "test ");
Map. Put ("password", "password ");

// JSON processing of the map object to be returned
Jsonobject Jo = jsonobject. fromobject (MAP );
System. Out. println ("*********");
// Call the tostring method of the json object to convert it to a string and assign it to result
String result = Jo. tostring ();
System. Out. println (result );

// [{"Name": "Age", "value": 10 },{ "name": "ID", "value": "1 "}, {"name": "name", "value": "name-1"}]
//*********
// {"Name": "test", "password": "password "}

}

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.