“bagaimana cara mengulangi jsonobject” Kode Jawaban

bagaimana cara mengulangi jsonobject

import org.json.JSONObject;

public static void printJsonObject(JSONObject jsonObj) {
    for (String keyStr : jsonObj.keySet()) {
        Object keyvalue = jsonObj.get(keyStr);

        //Print key and value
        System.out.println("key: "+ keyStr + " value: " + keyvalue);

        //for nested objects iteration if required
        //if (keyvalue instanceof JSONObject)
        //    printJsonObject((JSONObject)keyvalue);
    }
}
Smoggy Scarab

ITerate Through Json Object

var p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}
Motionless Meerkat

bagaimana cara mengulangi jsonobject

import org.json.JSONObject;

public static void printJsonObject(JSONObject jsonObj) {
    jsonObj.keySet().forEach(keyStr ->
    {
        Object keyvalue = jsonObj.get(keyStr);
        System.out.println("key: "+ keyStr + " value: " + keyvalue);

        //for nested objects iteration if required
        //if (keyvalue instanceof JSONObject)
        //    printJsonObject((JSONObject)keyvalue);
    });
}
Smoggy Scarab

bagaimana cara mengulangi jsonobject

JSONObject jsonObject = new JSONObject(contents.trim());
Iterator<String> keys = jsonObject.keys();

while(keys.hasNext()) {
    String key = keys.next();
    if (jsonObject.get(key) instanceof JSONObject) {
          // do something with jsonObject here      
    }
}
Smoggy Scarab

Jawaban yang mirip dengan “bagaimana cara mengulangi jsonobject”

Pertanyaan yang mirip dengan “bagaimana cara mengulangi jsonobject”

Lebih banyak jawaban terkait untuk “bagaimana cara mengulangi jsonobject” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya