I cannot find any explanation about why we use JSON when parsing it in Android?. Are we required to use it or is this just optional? What's the advantage and disadvantage of using it to extract data from the internet? Do we have to encode every data from PHP & MySQL into a JSON Format?
-
JSON has nothing specific to do with Android. You may wish to read more about JSON in reference sites, like [Wikipedia](https://en.wikipedia.org/wiki/JSON). – CommonsWare Apr 19 '16 at 17:17
-
You're absolutely right and I know that but I see a lot of tutorials when making login system, they always parse the JSON data from the remote server in order to exchange data with PHP & MySQL. – Muhammad Catubig Apr 19 '16 at 17:19
-
1That is because JSON is rather popular. You are welcome to use something else (XML, YAML, protobuf, Apache Thrift, etc.), if you like. For example, JSON is easy to read, but therefore it is more verbose than a binary packed format like protobuf. – CommonsWare Apr 19 '16 at 17:23
3 Answers
See this question. JSON is known as JavaScript Object Notation, it's a lot easier to parse then XML data, and there are libraries to help you retrieve the values from a JSON structure. As for the PHP & MySQL question, Android doesn't use MySQL, it uses SQLite instead. Hope this helps.

- 1
- 1

- 188
- 1
- 7
-
Yeah. You're right and I'm aware of that but if you are taking data from the remote database you will have to do some PHP and MySQL together right? – Muhammad Catubig Apr 19 '16 at 17:17
-
Yes. Your app should never directly communicate with your MySQL server, only the PHP, which you will have to get a response from. Look into making [POST and GET requests](http://www.tutorialspoint.com/php/php_get_post.htm). – Kolten Sturgill Apr 19 '16 at 17:19
-
Yeah so to get a response do we have to encode into JSON and parse it in Android? – Muhammad Catubig Apr 19 '16 at 17:20
-
JSON is just a format to represent Objects in textform. Its used often in Android because its nice to work with and has many libraries to help parse it.
Sometimes other formats are used like XML or something else to represent the data.

- 735
- 10
- 37

- 4,616
- 3
- 21
- 29
-
If it's nice to work with then it is optional to use it? What if I don't want to use any of the formats? For example, Just directly echo out the data from PHP & MySQL database then extract the information from android without parsing JSON or XML. – Muhammad Catubig Apr 19 '16 at 17:24
-
If you can get the data from the database in another format you can just use that format. – Joakim Ericsson Apr 19 '16 at 17:26
-
You can use any communication protocol you want, json is just an accepted standard. You can't just 'dump the mysql database' to the app, there has to be some sort of communication protocol that the server and client agree on to transport the data.
Some alternatives are xml or a binary format (such as protobuf).
I'd recommend json due to the abundance of tools and literature on it.
(Heres a blog post I wrote on using Jackson to parse json in Android http://shmuelrosansky.com/jackson/android/2015/07/20/jackson-android/)

- 3,916
- 2
- 27
- 45