Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
1  
Can you link to one of those discussions, cause I don't understand what you are asking here? –  Martin Wickman Mar 8 '13 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 Mar 8 '13 at 16:45

1 Answer 1

up vote 1 down vote accepted

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

  1. Come up with a data format,
  2. Write a parser for it, and
  3. 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.