Обратный порядок ключей JSONObject

Я искал во многих источниках, но не смог найти ответ на этот вопрос..

Известно, что ключи JSONObject возвращаются в обратном порядке.

Есть ли способ пройти через JSONObject в правильном порядке, как в JSON

String json;
JSONObject obj = new JSONObject(json)
Iterator<String> keys = json.keys()   ---> order is reversed

Я понимаю, что JSONObject неупорядочен, возможно, есть способ заказать его????

JSON имеет тип ниже... и ключи начинают возвращаться из самого нижнего тега styleHint

"sections": {


 "1": {
    "1": {
      "1": {
        "title": "xxx",
        "text": "xxx",
        "tags": {
          "audience": {
            "1": {
              "name": "xxx",
              "title": "xxx",
              "id": "xxx"
            }
          },
          "styleHint": {
            "1": {
              "name": "xxx",
              "title": "xxx",
              "id": "xxx"
            }
          }
        }
      },
      "title": "xxx",
      "text": "xxx",
      "tags": {
        "audience": {
          "1": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        },
        "styleHint": {
          "1": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        }
      }
    },
    "2": {
      "title": "xxx",
      "text": "xxx",
      "tags": {
        "audience": {
          "1": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        },
        "styleHint": {
          "1": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        }
      }
    },
    "title": "xxx",
    "text": "xxx",
    "tags": {
      "audience": {
        "1": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxx"
        },
        "2": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxx"
        }
      },
      "styleHint": {
        "1": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxx"
        }
      }
    }
  },
  "2": {
    "title": "xxx",
    "text": "xxx",
    "tags": {
      "audience": {
        "1": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxx"
        }
      },
      "styleHint": {
        "1": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxx"
        }
      }
    },
    "anchor":"xxx"

  },
  "3": {
    "1": {
      "title": "xxx",
      "text": "xxx",
      "tags": {
        "audience": {
          "tag": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        },
        "styleHint": {
          "tag": {
            "name": "xxx",
            "title": "xxx",
            "id": "xxx"
          }
        }
      }
    },
    "title": "xxx",
    "text": "xxx",
    "tags": {
      "audience": {
        "1": {
          "name": "xxx",
          "title": "xxx",
          "id": "xxxx"
        }
      },
      "styleHint": {
        "1": {
          "name": "xx",
          "title": "xxx",
          "id": "xxxx"
        }
      }
    }
  }  
}

1 ответ

Как насчет этого

Получите ваш источник org.json.JSONObject и измените их

public ListIterator keys() {
    ListIterator iter = new ArrayList(this.keySet()).listIterator();
    return iter;
}

а также

/**
 * Construct an empty JSONObject.
 */
public JSONObject() {
    this.map = new LinkedHashMap();
}

а также

/**
 * The map where the JSONObject's properties are kept.
 */
private final LinkedHashMap map;

а также

public JSONObject(Map map) {
    this.map = new LinkedHashMap();
    if (map != null) {
        Iterator i = map.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry e = (Map.Entry) i.next();
            Object value = e.getValue();
            if (value != null) {
                this.map.put(e.getKey(), wrap(value));
            }
        }
    }
}

Я надеюсь, что я не горю в аду за это.

Другие вопросы по тегам