I need to parse the server response from my http post & puts. I originally thought all responses were going to be XML. Now I’m finding out that, for certain calls, the response I’m getting back is JSON. I have no control over the server, so changing this is not an option.
So,I need to decide the best way to detect the data type coming back from the server. My first thought would be to attempt to parse the response as a JSON. If a JSONException is thrown, assume it is XML.
Since I have no control over the server, I’m not sure I can count on the headers being correct.
Does anyone have any thoughts on the best approach?
As I had stated in my question, I had no control over the server and could not count on it to be set up correctly and/or be passing the appropriate headers. Otherwise, this would have been the obvious answer.
My original idea is what ended up working best:
“My first thought would be to attempt to parse the response as a JSON. If a JSONException is thrown, assume it is XML.”