Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

loop through json object javascript

var p = {
    0: "value1",
    "b": "value2",
    key: "value3"
};

for (var key of Object.keys(p)) {
    console.log(key + " -> " + p[key])
}
Comment

how to iterate over 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);
    }
}
Comment

how to iterate over 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);
    });
}
Comment

iterate over json data javascript

var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one:1, two:2, three:3, four:4, five:5 };

jQuery.each(arr, function() {
  $("#" + this).text("My id is " + this + ".");
  return (this != "four"); // will stop running to skip "five"
});

jQuery.each(obj, function(i, val) {
  $("#" + i).append(document.createTextNode(" - " + val));
});
Comment

how to iterate over 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      
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get element by rel attribute 
Javascript :: onclick change image javascript example 
Javascript :: javascript log html element as dom object 
Javascript :: expo react native send image to api 
Javascript :: iterate over array of objects javascript 
Javascript :: download jquery 
Javascript :: cannot use import statement outside a module 
Javascript :: javascript add text to li 
Javascript :: javascript string to lowercase 
Javascript :: check if two rectangles overlap javascript canvas 
Javascript :: how to get element by id 
Javascript :: if classlist contains js 
Javascript :: countdown in react js 
Javascript :: node js load css file 
Javascript :: convert to 24 hours format javasript 
Javascript :: e.target.text react 
Javascript :: jquery remove class 
Javascript :: firestore update array 
Javascript :: jquery map 
Javascript :: jquery change page on click 
Javascript :: react native backgrunde img 
Javascript :: javascript canvas to image 
Javascript :: toggle button javascript 
Javascript :: how to set a string 
Javascript :: server.js 
Javascript :: how to click on the datepicker date in jquery 
Javascript :: ifsc code validation regex 
Javascript :: js different 
Javascript :: javascript array size 
Javascript :: react prevstate 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =