Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create json in android

Tags:

json

android

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?

like image 495
santBart Avatar asked Jan 02 '12 22:01

santBart


People also ask

What is JSON object in Android?

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.

Does JSON work on Android?

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.

Where do I put JSON files on Android?

json file is generally placed in the app/ directory (at the root of the Android Studio app module).


1 Answers

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); 
like image 136
aromero Avatar answered Oct 04 '22 03:10

aromero