JSONObject.toString() gives different result in 2.2 than in 2.1 (.Net Date format)
-
28-09-2019 - |
Question
In Android 2.1 this
JSONObject o = new JSONObject();
o.put("MyDate", "/Date(1289334937639)/");
Log.d(TAG, o.toString());
produces
{"MyDate":"/Date(1289334937639)/"}
but in 2.2 it produces
{"MyDate":"\/Date(1289334937639)\/"}
I am talking to a .Net web service so the 2.2 version works correctly for me. How do I make 2.1 produce the same thing without breaking 2.2?
Thanks for your help.
Solution 2
I ended up with the following:
if (Build.VERSION.SDK_INT == 7) {
params = params.replaceAll("/", "\\\\/");
}
where params is the json already converted to a string. Ugly, but it works.
OTHER TIPS
Get the latest version of of JSON from http://www.json.org/java/
and integrate it to your code. You just need to change your imports I guess.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow