I am working on one requirement , where I need to get the length of below json and length of filters object in the entire json
attaching the json for refrence.
{
"employeeId": "41825",
"userId": "tawright",
"sourceSystem": "Visibility",
"loginId": "nudayaku",
"groupBy": "order",
"isPretty": false,
"limit": 10,
"offset": 0,
"sortBy": "so_date",
"sortOrder": "desc",
"filters": [{
"name": "type",
"value": "POS",
"op": "eq"
}],
"srpGoalHeaderId": 3069181,
"srpGoalQuotaId": 1750558,
"category": "PRD & SVC|AG",
"goalSheet": "2020 CS020 28-Jul-2019 to 25-Jul-2020",
"loggedInUser": "nudayaku",
"requestedScreen": "orderSearch.g2c"
}
Can some one help me how can i get the Length of the filters involved in this JSon.
I am getting the below error while i am parsing the JSOn
org.json.simple.JSONArray cannot be cast to org.json.JSONArray
import java.io.FileOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.sql.Timestamp;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.json.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cisco.export.utils.SFDbConnection;
import com.fasterxml.jackson.core.JsonParser;
//Assign value from Input Export JSon
JSONObject json = getJSONObject(getFilters());
String employeeId = (String) json.get("employeeId");
Long planId = (Long) json.get("planId");
Long srpGoalHeaderId = (Long) json.get("srpGoalHeaderId");
Long allocationId = (Long) json.get("allocationId");
String nodeName = (String) json.get("nodeName");
String erpPosFlag = (String) json.get("erpPosFlag");
Long soNumber = (Long) json.get("soNumber");
ObjectMapper mapper = new ObjectMapper();
JSONArray filters = (JSONArray) json.get("filters");
System.out.println("filters" +filters);
error log:
Exception is java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.JSONArray java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.JSONArray
Thanks, Nikhil
import org.json.JSONArray;toimport org.json.simple.JSONArray;and try again.