I have this JSON
{
"id":2,
"group_id":1,
"default_billing":"2",
"default_shipping":"2",
"created_at":"2018-10-03 16:12:55",
"updated_at":"2018-10-03 16:13:00",
"created_in":"Default Store View",
"email":"[email protected]",
"firstname":"Henry",
"lastname":"Arcila",
"store_id":1,
"website_id":1,
"addresses":[{
"id":2,
"customer_id":2,
"region":{
"region_code":"NY",
"region":"New York",
"region_id":43
},
"region_id":43,
"country_id":"US",
"street":[
"123 Oak Ave"
],
"telephone":"512-555-1111",
"postcode":"10755",
"city":"Purchase",
"firstname":"Henry",
"lastname":"Arcila",
"default_shipping":true,
"default_billing":true
}],
"disable_auto_group_change":0
}
That JSON I got from this line of code:
JSONObject json = new JSONObject(responseStrBuilder.toString());
Since I am extracting this from a REST query, I want to save that JSON in a variable and then extract each one of these fields that are inside the ADDRESSES :
firstname, lastname, region_code, region, region_id, country_id, street, telephone, postcode and city.
At the time of obtaining them I want to save them in different variables and have them stored because then in other REST responses I need to load another JSONObject those variables, an example is this:
JSONObject JshippingAddress = new JSONObject();
JshippingAddress.put("email", "[email protected]");
JshippingAddress.put("region", "New York");
JshippingAddress.put("region_id", 43);
JshippingAddress.put("region_code", "NY");
JshippingAddress.put("country_id", "US");
JshippingAddress.put("street", JCalle);
JshippingAddress.put("postcode", "10577");
JshippingAddress.put("city", "Purchase");
JshippingAddress.put("telephone", "512-555-111");
JshippingAddress.put("firstname", "Henry");
JshippingAddress.put("lastname", "Arcila");
At the moment they were HARD CODE, it is worth noting that they are in different classes so I keep GLOBAL variables in a controller.