I wish to create json looking like:
{"man": { "name":"emil", "username":"emil111", "age":"111" } }
within android. This is what I have so far:
JSONObject json = new JSONObject(); json.put("name", "emil"); json.put("username", "emil111"); json.put("age", "111");
Can anyone help me?
JSON stands for JavaScript Object Notation.It is an independent data exchange format and is the best alternative for XML. This chapter explains how to parse the JSON file and extract necessary information from it.
Android supports all the JSON classes such as JSONStringer, JSONObject, JSONArray, and all other forms to parse the JSON data and fetch the required information by the program. JSON's main advantage is that it is a language-independent, and the JSON object will contain data like a key/value pair.
json file is generally placed in the app/ directory (at the root of the Android Studio app module).
You can put another JSON object inside the main JSON object:
JSONObject json = new JSONObject(); JSONObject manJson = new JSONObject(); manJson.put("name", "emil"); manJson.put("username", "emil111"); manJson.put("age", "111"); json.put("man",manJson);
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