开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜