I'm trying to build a JSON string that looks like this:
{
"account": {
"description": "desc2",
"users": [
{
"user": {
"username": "Zogbi",
"password": "password1",
"firstName": "Tim",
"lastName": "Smith",
}
}
]
}
}
What's coming out is this, though:
{
"account": {
"users":[{
"middleName":"S","lastName":"Smith","username":"Zogbi","alias":"Gibbus","firstName":"Tim","password":"password1"
}
]
}
}
So, two problems: 1. I need a "Description" after the "account" 2. I need a "user" object that's part of the "users" array.
Here is my code:
JSONObject account = new JSONObject();
JSONArray users = new JSONArray();
JSONObject user = new JSONObject();
JSONObject mainObj = new JSONObject();
account.put("users", users);
users.put("user");
user.put("username", "Zogbi");
user.put("password", "password1");
user.put("firstName", "Tim");
user.put("lastName", "Smith");
user.put("middleName", "S");
user.put("alias", "Gibbus");
mainObj.put("account", account);
Any help is appreciated!