-3
{
  "Header": {
    "AppId": "appiddfdsf324",
    "RecId": "fdsfrecid79878_879898_8797",
    "SecureRefId": "fsdf5679567fsd_6789678",
    "Type": "Other",
    "Ver": "9.0.0",
    "StartTS": "2016-09-26:07:48.798798-04:00"
  }, 
  "Application": {
    "APP_OS": "Windows",
    "APP_Runtime": ".Net67986",
    "APP_AppName": "MPS",
    "APP_AppVersion": "9.0.0.0",
    "Host": "fsdhajkfh657895fsdajf",
    "Channel": "N/A",
    "APP_ReqId": "2f3d7987987-78987-987987-897-da"
  },
  "Service": {
    "Key": "modification process",
    "CallType": "HGDL",
    "Operation": "processrequest",
    "Port": "n/a"
  },
  "Results": {
    "Elapsed": 0,
    "Message": "Message Succesfully Deleted",
    "TraceLevel": "Information"
  },
  "Security": {
    "Vendor": "abfsdf"
  },
  "Extended_Fields": {
    "CustomerId": "4564987987",
    "MessageId": "768789fsdafasdf987987987fasdf",
    "TimeElapsed": "1272.8171"
  }
}

in above string value we are capturing from website result values we will get in a string format by using selenium webdriver. This i need to convert and read value of "Message"

Note : i have tried below code

JsonElement jelement = new JsonParser().parse((String) elementText);
JsonObject  jobject = jelement.getAsJsonObject();
jobject.getAsJsonObject("Results");

This above will provide complete result value of Result json but i required to fetch values which is present with "Message"

yanana
  • 2,241
  • 2
  • 18
  • 28
sunil wali
  • 13
  • 1
  • 5

1 Answers1

0

Below first line creates the JSONObject by passing String [which is of JSON format and it should be in JSON format, otherwise it will through an exception]

In Second line , as you have a JSON Object now, you can fetch any element from that,

e.g to fetch the value for Message, which is an element of "Results" object which is of JSON type, 

we can access any element by using . and depending on what are you fetching use get

e.g getString -> for getting String, 
    getInt->for getting Integer, 
    JSONObject-> for getting an JSONObject 
    getJSONArray-> for getting a JSONArray


JSONObject jsonObj=new JSONObject(pass your String) //This converts in to JSON Object
jsonObj.getJSONOObject("Results").getString("Message"); //As result internally itself is a JSON Object
Monis Majeed
  • 1,358
  • 14
  • 21
  • Code only answers are not allowed on SO. Please explain what the code does and how it answers the question so that it's more useful to the OP and future readers. – JeffC Sep 27 '16 at 17:07