Android create JSON string

Nowadays, JSON becomes a useful data-interchanges format that is easy to generate, transmit, and read by any programming language. It is an alternative to XML. You can create a
JSON string in Android and use it on Android or send it your web page. You can create a JSON string in PHP and transmit the string to an Android application which parses the string.
﻿

In this Android tip, I am going to show you how to create a JSON string in Android. In Android, there are two important classes used to generate a JSON string. They are JSONArray and JSONObject. In a JSONArray instance, you can store different type of data including JSONObject. Below is a JSON string that is created from a JSONArray that has three string items.
["Galaxy Note3","Galaxy S4","Galaxy S4"]

Here is another example JSON string. This JSON string created from a JSONArray that has two JSONObject instances. In each JSONObject instance, there are three pairs of name and value. cid, cphone, and cname are names. 1, 855233098, Dara Sok are values.

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.