JSON命令混淆了 [英] JSON order mixed up

查看:155
本文介绍了JSON命令混淆了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的页面按照我想要的顺序打印 JSONObject 时遇到问题。在我的代码中,我输入了这个:

I've a problem trying to making my page printing out the JSONObject in the order i want. In my code, I entered this:

JSONObject myObject = new JSONObject();
myObject.put("userid", "User 1");
myObject.put("amount", "24.23");
myObject.put("success", "NO");

然而,当我在页面上看到显示时,它会给出:

However, when I see the display on my page, it gives:

JSON格式化字符串: [{成功:否,用户ID:用户1,出价:24.23}

JSON formatted string: [{"success":"NO","userid":"User 1","bid":24.23}

我需要按用户ID,金额,然后成功的顺序。已经尝试在代码中重新排序,但无济于事。我也试过 .append ....在这里需要一些帮助谢谢!!

I need it in the order of userid, amount, then success. Already tried re-ordering in the code, but to no avail. I've also tried .append....need some help here thanks!!

推荐答案

你不能也不应该依赖JSON对象中元素的排序。

You cannot and should not rely on the ordering of elements within a JSON object.

来自 http://www.json.org/


对象是一组无序的
名称/值对

An object is an unordered set of name/value pairs

因此,
JSON库是免费的按照他们认为合适的方式重新排列元素的顺序。
这不是错误。

As a consequence, JSON libraries are free to rearrange the order of the elements as they see fit. This is not a bug.

这篇关于JSON命令混淆了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆