I am working with Orchestration Design, but found that it doesn't have all the functions I need, so we have a lot of hard coded JAVA.
I have read several post discussing similar errors as below.
org.codehaus.jettison.json.JSONException: JSONObject["customer"] not found
I have tried several of the solutions that were previously published, but am still not able to get this fixed. I have only 2 weeks of java training, and next to no real world experience with Java. So if you can break it down or provide more guidance I would be really appreciative. Here is my data:
{"statusCode":"200",
"statusMessage":"OK",
"data":
{"customer":
[{"name":"John Smith",
"dob":"06-14-2000",
"phones":
[{"phoneID":"d3dd30b1-cd47-46f5-8e06-1fd5e8631203",
"phoneNumberTypeCode":"3",
"phoneNumber":"2162100834",
"sortOrderCode":"1"},
{"phoneID":"0153632c-ae8f-4b12-a68f-1ab33fa4e7e3",
"phoneNumberTypeCode":"3",
"phoneNumber":"3306973358",
"sortOrderCode":"2"}]},
{"name":"same five",
"dob":"06-01-1968",
"phones":
[{"phoneID":"83c49dd0-d308-4e88-b25e-4ddff53bf124",
"phoneNumberTypeCode":"3",
"phoneNumber":"3306973358",
"sortOrderCode":"1"}]},
{"name":"same five",
"dob":"06-01-1968",
"phones":
[{"phoneID":"ac61e9ce-ea4e-46c3-85d7-cd07bdcbf54e",
"phoneNumberTypeCode":"3",
"phoneNumber":"3306973358",
"sortOrderCode":"1"}]},
{"name":"kjhdv askljdh",
"dob":"06-01-1968",
"phones":
[{"phoneID":"8706e547-c9fe-4844-84a8-f4c78abd7277",
"phoneNumberTypeCode":"3",
"phoneNumber":"3306973358",
"sortOrderCode":"1"}]}]}}
At this point I am only interested in getting to the DOB. I need to compare it to data entered by a customer to try pull the correct account. Later on I will need to get to the rest of the data, but I hope once I understand how to get to the DOB I can figure the rest out on my own.
Here is the code I have been writing. I have a lot of commented out code which was examples I found on this forum and tried to get to work as well. Each version give me an error
JSONObject["customer"] not found.
I do realize that there are other posts with this same issue, but I have not been able to make any of the solutions work for me (probably due to my lack of experience)
public String getAccount(String requestUrl, String token) throws Exception {
String statusmessage = "";
try {
CloseableHttpClient httpClient = getHttpClient();
HttpGet getRequest = new HttpGet(requestUrl);
getRequest.addHeader("accept", "application/json");
getRequest.addHeader("Authorization", token);
HttpResponse response = httpClient.execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
System.out.println("StatCode = "
+ response.getStatusLine().getStatusCode());
return "500";
//throw new Exception("Failed : HTTP error code : " +
//response.getStatusLine().getStatusCode());
}
String responseStr = EntityUtils.toString(response.getEntity());
System.out.println("RESPONSE *** " + responseStr);
String jsonResp = responseStr;
JSONObject jsonObj = new JSONObject(jsonResp);
statusmessage = jsonObj.get("statusMessage").toString();
System.out.println("StatusMes : " + statusmessage);
String data = jsonObj.get("data").toString();
System.out.println("Data : " + data);
//String customer = jsonObj.get("customer").toString();
JSONArray customer = jsonObj.getJSONArray("customer");
for(int i=0;i<customer.length();i++)
{
JSONObject jb1 = customer.getJSONObject(i);
String name = jb1.getString("name");
}
//JSONObject jObject = new JSONObject(response);
// JSONArray jsonArray = jObject.getJSONObject("response").getJSONArray("Message");
// for (int i = 0; i < jsonArray.length(); i++) {
// JSONObject objJson = jsonArray.getJSONObject(i);
//}
//TopTenGetterSetter obj = new TopTenGetterSetter();
/* JSONArray Customer = jsonObj.getJSONArray("customer");
String customer = Customer.getJSONObject(0).getString("name");
for (int i = 0; i < Customer.length(); i++) {
String name = Customer.getJSONObject(i).getString("name");
System.out.println(name);
String dob = Customer.getJSONObject(i).getString("dob");
System.out.println(dob);
String phones = Liste.getJSONObject(i).getString("phones");
System.out.println(phones);
String Position = Liste.getJSONObject(i).getJSONObject("Position").toString();
System.out.println(Position);
*/
//JSONObject outerObject = new JSONObject(jsonResp);
//JSONObject innerObject = outerObject.getJSONObject("JObjects");
//JSONArray jsonArray = innerObject.getJSONArray("JArray1");
//for (int i = 0, size = jsonArray.length(); i < size; i++) {
// JSONObject objectInArray = jsonArray.getJSONObject(i);
// "...and get their component and their value."
//String[] elementNames = JSONObject.class.getName(objectInArray);
//for (String elementName : elementNames) {
// String value = objectInArray.getString(elementName);
//}
Thank you,