嗨,我有以下字符串
[{"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/