How do I get the numbers 215, 248, 252 from Json?



  • I know that in Json data 30 objects. How do I get the numbers 215, 248, 252 etc. without knowing them first? If they were in the mass, I could indicate the type 0 1 2 3 4 5... ♪

    {
    "status":"success",
       "data":{
         "215":{},
         "248":{},
         "252":{},
         "267":{
    


  • Since you want standard equipment, there's no way, unless you manually walk through the object's keys, get the keys on these keys and put them in the body. But order. JsonObject not guaranteed. JsonArray consists only of values, not of key value. Description json The format can be seen here - http://www.json.org/json-ru.html Maybe a lot of things will be clear.

    If you control the creation of json, you can lead to this kind of thing:

    {
      "data": [
        {
          "A1": {
            "key1": 123
          }
        },
        {
          "A2": {
            "key2": 456
          }
        }
      ]
    }
    

    Then data can be transformed into JsonArray and the index values can be obtained.

    UPD:Only keys can be obtained:

    JSONObject jsonObject;
    //получаем jsonObject 
    JSONObject dataObject = jsonObject.getJSONObject("data");
    for(Iterator<String> keys = dataObject.keys(); keys.hasNext(); ) {
        String key = keys.next();
        // что-то делаем с ключом
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2