I need to convert a ArrayList
of String
to a JSON.
I have a method where I get a list of apps installed on the mobile device. This method returns the data in a String ArrayList.
I was able to generate a JSON using JSONArray
but I was unable to insert a tag inside Json, it follows JSON using JSONArray
.
Json: ["com.br.package1", "com.br.package2", "com.br.package3"]
I need Json to look like this:
[{"name": "com.br.package1"},{"name": "com.br.package2"}, {"name":"com.br.package3"}]
Here is an excerpt from the code:
//Cria e inicializa ArrayList que contem os packages instalados no Aparelho
ArrayList<String> mPackages = new ArrayList<String>();
//Grava no ArrayList o retorno do método
mPackages = Util.buscaAppsInstalados(getBaseContext());
JSONArray jsonArray = new JSONArray(mPackages);