I am having one hell of a time trying to read a JSON object that is being passed from a URL from one my web pages. I need to be able to parse the data an insert into into our database. I have searched high and low all over this site as well as many others and still cannot get anything to work. Here is my last exhausted resource which still does not work.
Accessing members of items in a JSONArray with Java
Here is the object that is coming in.
{
"tableData": [{
"id": 1,
"inspReq": "test1",
"inspInit": "",
"inspComm": "testing"
}, {
"id": 2,
"inspReq": "test2",
"inspInit": "bmb",
"inspComm": "more%20testing"
}, {
"id": 3,
"inspReq": "test3",
"inspInit": "abc",
"inspComm": "another%20test"
}]
}
<%@ include file="faSite.jsp"%>
<%@ page import="org.json.simple.JSONObject"%>
<%@ page import="org.json.simple.JSONArray"%>
<%@ page import="org.json.simple.parser.ParseException"%>
<%@ page import="org.json.simple.parser.JSONParser"%>
<%
try{
String json = request.getParameter("jsonData");
JSONParser parser = new JSONParser();
Object obj = parser.parse(json);
System.out.println("created object");
System.out.println(obj);
JSONArray array = new JSONArray();
array.add(obj);
System.out.println("created array");
System.out.println(array);
for(Object o: array){
System.out.println("inside JSON array");
JSONObject jsonLineItem = (JSONObject) o;
String inspReq = jsonLineItem.getString("inspReq");
}
}catch(Exception e){
e.printStackTrace();
}
%>
Here is my error.
500 Internal Server Error
Error parsing JSP page /production/FirstArticle/core/faPost.jsp Syntax error in source /production/FirstArticle/core/faPost.jsp.java:211: error: cannot find symbol (JSP page line 24)
String inspReq = jsonLineItem.getString("inspReq");
^
symbol: method getString(String)
location: variable jsonLineItem of type JSONObject
Note: /production/FirstArticle/core/faPost.jsp.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
It is making it into the array and I am able to see the object on a log but once it tries to get the string, it fails.