I have a JSON Object such as the following:
{
"username":"bobgreen"
"forename":"Bob"
"surname":"O'Conor"
}
{
"username":"jacksmitd"
"forename":"Jack"
"surname":"Smitd"
}
{
"username":"samson"
"forename":"Sam"
"surname":"Son"
}
I am not sure how to put this data into the hashmap
.
So far I have something like this:
// What is returned from the server in JSON format
JSONObject jsonObj = new JSONObject(serverData);
I don't know how to proceed from here
SORRY - I want to pass the following values "username"
, "forename"
, "surname"
into the following constructor - Personnel(String username, String forename, String surname)
But I don't know how to do the for-loop
?
I had something like:
for(int i=0; i<jsonObj.size(); i++){
personnel = new Personnel(jsonObj.get("username"), jsonObj.get("forename"), jsonObj.get("surname"));
}
Obviously that won't work - but I hope you understand what I am trying to achieve