1

From the below JSON, I want to display the Query string. I have done it by using JSON parser.

{
    "group By": "name",
    "time Period": {
        "from": "2015-12-29",
        "to": "2016-02-29"
    },
    "query String": "[nation]: \"India\" AND [education]: \"be",
    "geography": "NA",
    "offset": 0,
    "limit": 10
}

While running, it shows error as

Exception in thread "main" org.json.JSONException: JSONObject["query String"] is not a JSONObject.

My JSON query is:

String request  = rs.getString("Request");
JSONObject jsonObject = new JSONObject(request);
JSONObject newJSON = jsonObject.getJSONObject("groupBy");
String input = newJSON.toString();
1
  • 1
    Your code doesn't ask for query String at all - although it does ask for groupBy as if it were a JSON object, which it's not, and by the wrong name. The code you've given doesn't match the error you've shown. Please provide a minimal reproducible example. Commented Mar 1, 2016 at 8:03

1 Answer 1

1

If you just want to get the "query String" of your json. I got it working with this part of code:

String json = "{ \"group By\": \"name\", \"time Period\": { \"from\": \"2015-12-29\", \"to\": \"2016-02-29\" }, \"query String\": \"[nation]: \\\"India\\\" AND [education]: \\\"be\\\"\", \"geography\": \"NA\", \"offset\": 0, \"limit\": 10 }";
JSONObject jsonObject = new JSONObject(json);
String input = (String) jsonObject.get("query String");

The output of input is:

[nation]: "India" AND [education]: "be"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.