Okay I’m really sorry if this question has been asked, but I can’t seem to find any good help on this.
I coded myself a little API for my android app using PHP and Codeigniter. It works through GET requests, so I’ll send it some info and it’ll return something. When I send it a login request, I want it to validate the user data, and if correct return the user’s credentials (uid, email, etc). All of this information can either be returned as formatted XML or a JSON array. My question is which would be easier to work with in Java, and can you help me with a quick example?
Any help is much appreciated.
EDIT:
Requested Code
// Parse JSON array
JSONObject obj = (JSONObject) JSONValue.parse(response);
String uid = (String) obj.get("uid");
String email = (String) obj.get("email");
From my experience, JSON is much easier to work with.
This is some data formatted in XML:
Here is sample code to read the XML file:
And this is the same data formatted in JSON:
And the sample code to read the JSON:
From the 2 piece of sample codes, you can see that JSON is much easier to read, write, and format.
XML is more commonly used as the industry standard for exchanging information, while JSON is commonly used to exchange information via REST-based APIs.