java


Unable to read JSON array in java


I have some JSON data which looks as follows
{logs:[{"Log_Level":"Info","appTypeName":"WebNodeJS","Log_Thread":"1492451392226","Log_Component":"Monitoring.WebNodeJS","EntryType":"LogEvent","Log_Message":"Widget Render Time","Log_DateTime":"2017-04-17T17:49:52.226Z","DashboardId":"58f4f4f93b143a902a000022","DashboardName":"Dashboard","DashboardLoadTime":2830,"DashboardRefreshTime":855,"WidgetId":"58f4f4f93b143a902a000024","WidgetName":"Rich Text","WidgetQueryTime":0,"WidgetLoadTime":1888,"WidgetRenderTime":2,"WidgetType":"richtexteditor"},
{"Log_Level":"Info","appTypeName":"WebNodeJS","Log_Thread":"1492451392226","Log_Component":"Monitoring.WebNodeJS","EntryType":"LogEvent","Log_Message":"Widget Render Time","Log_DateTime":"2017-04-17T17:49:52.226Z","DashboardId":"58f4f4f93b143a902a000022","DashboardName":"Dashboard","DashboardLoadTime":2830,"DashboardRefreshTime":855,"WidgetId":"58f4f4f93b143a902a000027","WidgetName":"Top 10 Expensive Cases","WidgetQueryTime":508,"WidgetLoadTime":979,"WidgetRenderTime":86,"WidgetType":"chart/bar"}]}
This is my code to read it. I would like to extract the individual elements WidgetLoadTime elements from it. However, it gives me the following error.
public void preProcess() throws FileNotFoundException, IOException, ParseException
{
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("file.json"));
JSONObject jsonObject = (JSONObject) obj;
System.out.println(jsonObject);
// loop array
JSONArray msg = (JSONArray) jsonObject.get("");
Iterator<String> iterator = msg.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}

Related Links

Hibernate Criteria fails to find results when apostrophe is present
Is this a reasonable approach for my Java web app? [closed]
how can i check internet connectivity before executing HTTPClient [duplicate]
ZipOutPutStream, ZipEntry return null when I try to dezip
EventQueue error when passing variables between two JFrames
Exact steps to kill Hadoop 2.2.0 Configuration deprecation info messages
Java equivalent from Obj C
How to get an object to “know” it's a node in a LinkedList?
Why this cannot be used in the main method of a Java class?
Java annotations tutorial [closed]
Terrain/Mountain algorithm not working as intended
s:form tag action parameters being removed
JAVA HTTP Client and Serlvlet
How to send an SMS using the power button through an Android application running in the background?
httpPost setEntity always empty
String index out of range: -1 on String comparison

Categories

HOME
amazon-ec2
dictionary
relay
alpha
ebean
enterprise-library-5
convolution
adfs
kibana-4
user-input
spring-xd
modx-revolution
designer
lombok
seaborn
ef-migrations
openedx
nas
scriptcs
subdomains
google-cloud-endpoints-v2
vsts-build-task
cloud-code
overlap
file-format
hilbert-curve
webdriver-manager
mime
qwt
strptime
upstart
errordocument
pnotify
clean-architecture
datastax-startup
aurelia-validation
diagnostics
google-perftools
capacity
pillow
spring-mongodb
sonarlint-vs
chord-diagram
deadbolt-2
libpng
httplistener
storekit
fputcsv
simplewebrtc
superstack
bluemix-app-scan
apachebench
pundit
0xdbe
bridge.net
jscript.net
phalanger
mdt
titanium-modules
document-classification
zend-route
flask-cors
contenttype
marmalade
mysqltuner
quantlib-swig
access-rights
listings
dbconnection
random-seed
plasma
type-equivalence
ocunit
kyotocabinet
tinn-r
parametric-equations
nsdatecomponents
coredump
psi
hamachi
xtype
jmock
xfbml
h.323
suppress
nhibernate.search
uimenucontroller
django-notification
lzh

Resources

Encrypt Message