I want to program a nested JSON Object for my Android device, but how? I have only basic experience with Json, so I would appreciate if someone could help me with the following code:
{
"command": "login",
"uid": "123123123",
"params":
{
"username": "sup",
"password": "bros"
}
}
Edit:
The following code does solve the problem:
loginInformation = new ArrayList();
JSONObject parentData = new JSONObject();
JSONObject childData = new JSONObject();
try {
parentData.put("command", "login");
parentData.put("uid", UID.getDeviceId());
childData.put("username", username.getText().toString());
childData.put("password", password.getText().toString());
parentData.put("params", childData);
} catch (JSONException e) {
e.printStackTrace();
}
loginInformation.add(new BasicNameValuePair("content", parentData.toString()));
解决方案
You need to create a JSON, and add that JSON as a parameter in your POST. To do that you should probably :
post.add(new BasicNameValuePair("data",json.toString());
You could use org.json.JSONObject, it is included in the Android SDK.