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<NameValuePair>(); 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()));
Objects can be nested inside other objects. Each nested object must have a unique access path. The same field name can occur in nested objects in the same document.
Nested JSON is a JSON file with a big portion of its values being other JSON objects.
Attributes and event data can contain nested (JSON) values—arrays, objects, and arrays of objects. You can use these nested values to match people in segments, filters, and trigger criteria.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With