0

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.

Judah Sali
  • 1,088
  • 1
  • 7
  • 12

2 Answers2

0

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.

Caner
  • 57,267
  • 35
  • 174
  • 180
  • Thanks for the suggestion. I think I have the latest json version in eclipse, but it looks like the 2.1 emulator (and I confirmed this on a motorola droid running 2.1) uses a different version than the 2.2 emulator. That is, the same code (same imports) produces two different results depending on the version of android. Can I force the emulator/device to use the version of json I want it to use? – Judah Sali Dec 23 '10 at 18:59
0

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.

Judah Sali
  • 1,088
  • 1
  • 7
  • 12