开发者

JSONObject.toString() gives different result in 2.2 than in 2.1 (.Net Date format)

开发者 https://www.devze.com 2023-01-27 04:56 出处:网络
In Android 2.1 this JSONObject o = new JSONObject(); o.p开发者_C百科ut(\"MyDate\", \"/Date(1289334937639)/\");

In Android 2.1 this

JSONObject o = new JSONObject();
o.p开发者_C百科ut("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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号