1

I am writing an android application which interacts with a Rest api which replies back with json object to the applicatoin. I need to get a particular property from that json object (I need to have both key and value of that property). I am using Google volley to access the API.

For Example, Below is a response from the API. I want to extract the property "context" with it's value from the output below, means i want to have the context Object from the output:

{
    "input": {
        "text": ""
    },
    "context": {
        "conversation_id": "xxxxxxxxxxxxxxxxxxx",
        "system": {
            "dialog_stack": [
                "Welcome"
            ],
            "dialog_turn_counter": 1,
            "dialog_request_counter": 1,
            "_node_output_map": {
                "Welcome": [
                    0
                ]
            }
        }
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Roohi Zuwairiyah
  • 363
  • 3
  • 15
  • Sounds like you want/need a database. Volley isn't the problem here, really - your code (mostly) looks fine. You have to do more than Toast in the response. – OneCricketeer Mar 02 '17 at 06:19
  • Please check the post again, i made it more precise and clear. I think you'll understand it now. What exactly the problem, I am facing. Thanks – Roohi Zuwairiyah Mar 02 '17 at 06:34
  • if you know the name of the key then you can check for the value using JsonObject.has("yourKeyHere") (Context in your case) it will return true if there is a mapping exists [see this link for more info](https://developer.android.com/reference/org/json/JSONObject.html#has(java.lang.String)) – Sony Mar 02 '17 at 06:44
  • 1) Why did you delete your code? 2) Do you have a Gson object for the `"context"` key? Note: You shouldn't name it `Context` because that is an Android class. – OneCricketeer Mar 02 '17 at 06:44

0 Answers0