JSONObject.toString() 在 2.2 中给出的结果与 2.1 中不同(.Net 日期格式)

发布于 2024-10-04 21:08:02 字数 403 浏览 1 评论 0原文

在 Android 2.1 中,它

JSONObject o = new JSONObject();
o.put("MyDate", "/Date(1289334937639)/");
Log.d(TAG, o.toString());

会产生

{"MyDate":"/Date(1289334937639)/"}

,但在 2.2 中,它会产生

{"MyDate":"\/Date(1289334937639)\/"}

我正在与 .Net Web 服务交谈,因此 2.2 版本对我来说可以正常工作。如何在不破坏 2.2 的情况下使 2.1 产生相同的结果?

感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇妻 2024-10-11 21:08:03

http://www.json.org/java/ 获取最新版本的 JSON 并将其集成到您的代码中。我猜你只需要改变你的进口。

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.

东走西顾 2024-10-11 21:08:03

我最终得到以下结果:

if (Build.VERSION.SDK_INT == 7) {
    params = params.replaceAll("/", "\\\\/");
}

其中 params 是已经转换为字符串的 json。丑陋,但它有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文