@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Try {
// Generate JSON data 1
// First, the outermost layer
JSONObject resultJsonObject = new JSONObject ();
// Phones is an array, so JSONArray is created.
JSONArray phonesJsonArray = new JSONArray ();
// JSONArray saves data
PhonesJsonArray. put ("028-123456"). put ("15002806555 ");
// Save the outermost layer
ResultJsonObject. put ("phones", phonesJsonArray );
// Save the outermost layer
ResultJsonObject. put ("name", "Xiaoqiang ");
// Save the outermost layer
ResultJsonObject. put ("age", 17 );
// Address is an object, so JSONObject is created.
JSONObject addressJSONObject = new JSONObject ();
AddressJSONObject. put ("country", "china ");
AddressJSONObject. put ("province", "Sichuan ");
// Save the outermost layer
ResultJsonObject. put ("address", addressJSONObject );
// Save the outermost layer
ResultJsonObject. put ("married", false );
System. out. println ("resultJsonObject. toString () =" + resultJsonObject. toString ());
System. out. println ("--------------------------------------------------");
System. out. println ("married =" + married + ", country =" + country + ", province =" + province + ", age =" + age + ", name =" +
Name + ", phoneNumber1 =" + phoneNumber1 + ", phoneNumber2 =" + phoneNumber2 );
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.