After running my script, I receive an array (JSON Array) structured like this:
[{redirectCount=0, encodedBodySize=60962, unloadEventEnd=0, responseEnd=1601.699999999255, domainLookupEnd=995.7999999896856, ...
Now, I want to display the key-value pairs from the array similar to how I would do so with a Map:
Map<String, ?> map = cap.asMap();
for ( Map.Entry<String, ?> entry : map.entrySet())
{
System.out.println(entry.getKey() + " value is " + entry.getValue());
}
I have attempted some resources online but haven't had any success yet:
- How can i print json objects and array values?
- How to Print JSON Array returned from controller class to jsp page
- JSON - Iterate through JSONArray
I'm wondering if the JSON format that I am receiving is different from the standard formats?
The current code I am using for this task involves Selenium and Javascript to extract performance statistics:
String netData = ((JavascriptExecutor)driver).executeScript(scriptToExecute).toString();
System.out.println(netData);
The JavaDocs of executeScript()
function specifies how various data types are handled when returning values:
- For an HTML element, it returns a WebElement
- For a decimal, a Double is returned
- For a non-decimal number, a Long is returned
- For a boolean, a Boolean is returned
- In other cases, a String is returned.
- For arrays, it returns a List with each object following specific rules. Nested lists are supported.
- For maps, it returns a Map following the specified rules.
- If the value is null or there is no return value, it returns null