android - JSONArray 在不同设备上的奇怪输出

标签 android json

嗨,我有以下字符串

 [{"SUBSCRIBERID":"151-52-049","LONG":"46.69127274","LAT":"24.70912743"},{"SUBSCRIBERID":"151-29-016","LONG":46.69570000","LAT":"24.70770000"}]

我正在将此字符串转换为 JSONArray

JSONArray jsonArrr = new JSONArray(String);

然后循环数组并获取 JSONObject

for (int h = 0; h < jsonArrr.length(); h++) {

    jsonObj = jsonArrr.getJSONObject(h);
    Iterator<String> iter = jsonObj.keys();
    Object valuee = "";
    String key = iter.next();
    Log.e(TAG, "key is: " + key);
    try {

        valuee = jsonObj.get(key);
        Log.e(TAG, "key: " + key + "---value: " + valuee);   //on htc key is SUBSCRIBERID and its value while on samsung key is LONG and its valuee!!
    } catch (JSONException e) {

        Log.e(TAG,"SOME ERROR: "+e);
    }

在此 for 循环中,检索到的值是每个对象中的第一个值。 在我的 HTC 手机上,第一个值正确显示为在三星设备上购买的 SUBSCRIBERID 值,第一个值显示为 LONG。

请提供任何帮助,我们将不胜感激!!

最佳答案

按键的顺序未定义。因此,如果您在不同的设备上执行代码,您可能会看到不同顺序的 key 。 REF

Returns an iterator of the String names in this object. The returned iterator supports remove, which will remove the corresponding mapping from this object. If this object is modified after the iterator is returned, the iterator's behavior is undefined. The order of the keys is undefined.

关于android - JSONArray 在不同设备上的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30253504/

相关文章:

json - 不带 JSONP 的 getJSON 远程请求 - 服务器

python - Pickle 拒绝使用 celery 报告 ContentDisallowed : Refusing to deserialize untrusted content of type pickle 来序列化内容

json - 从字典键中提取值 - 然后组合成一个对象

java - 从 JSON 对象填充 JTable

android - 如何在安装在 Android 上的应用程序中创建链接以打开 Instagram 页面?

java - MediaPlayer 在使用 Handler 时出现滞后

android - 在 webview 中过早调用滑动刷新

java - onConfigurationChanged() 未在方向更改时调用

java - 谷歌服务器验证码导致登录失败

php - 我有两个临时变量,如何在 PHP 中比较它们?