I have seen some tutorials and some stackoverflow discussions on how to send data from android to php page. most of the cases i have seen people sending data in string format but returning in json format. My question is that is it better to send data from android to php in json format. or in what cases i should use json over string.
Regards
-
1Can you link to one of those discussions, cause I don't understand what you are asking here?Martin Wickman– Martin Wickman2013年03月08日 15:20:56 +00:00Commented Mar 8, 2013 at 15:20
-
1"string" is not a format. A "string" format is the way a string is organized. Json is a string format (with specific requirements). 'Plan Text' is a string format (with very loose requirements).Loki Astari– Loki Astari2013年03月08日 16:45:09 +00:00Commented Mar 8, 2013 at 16:45
1 Answer 1
Why do most people send just a string to a php page, instead of a JSON object? Probably because they just need to send one item of data; usually it's an ID, like a Customer ID.
JSON is a structured data format. It works seamlessly with Javascript, and benefits from the easy availability of well-written parsers. It is used to return an object containing fields of data.
To do the same things as JSON does using strings, you would have to
- Come up with a data format,
- Write a parser for it, and
- Map the resulting data fields to Javascript variables.
All that work is already done for you, if you choose JSON. That's why it is used to return, for example, a customer record from a database.