I Tring to monitor my site performance day by day activity with help of google api
and i tried to fetch items in network request from googleapi of pagespeedonline
but its not working on my code
REST API link :
and i try to get particularly
lighthouseResult -> audits -> network-requests ->details-> items
and store each items into record...
i tried below codes
package FirstTestNgPackage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.json.*;
public class testingJSON {
static String inline = "";
public static void main(String args[]) throws JSONException, InterruptedException, IOException {
// url
URL url = new URL("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://lifemachi.blogspot.com&key=AIzaSyBfHVlhNEnf26Ea8-ZOhiYOe0HrQZtLvRI&category=performance&strategy=desktop");
// read it from URL
Scanner sc = new Scanner(url.openStream()); Thread.sleep(300);
String jsonDataString = sc.nextLine();
while(sc.hasNext())
{
inline+=sc.nextLine();
}
sc.close();
List<String> list = new ArrayList<String>();
// just print that inline var
System.out.println(inline);
System.out.println("--------1");
}
}
and i got proper output... but how to store items values in list ?
Thanks in advance
If you only want to retrieve the JSON array
items
in whole JSON response, it can be easily done by usingJsonPath
as follows:Code snippet
Maven dependency