'can't get the Element of JSON Object
I have a jsonobject that contains some json objects
"paths": {
"/api/{version}/RAW/getrawdata": {
"get": {
"tags": [
"RAw"
],
"summary": "/getrawdata",
"parameters": [
{
"name": "token",
"in": "header",
"description": "gettoken",
"schema": {
"type": "string"
},
"/api/{version}/filtered/getfinaldatadata": {
"get": {
"tags": [
"filtered"
],
"summary": "/getfinaldatadata",
package beans;
import org.apache.camel.Exchange;
import org.apache.camel.Header;
public class URIpattern {
@SuppressWarnings("deprecation")
public String URI(JSONObject json,
@Header (Exchange.SLIP_ENDPOINT) String previous) {
if(previous!=null){
return null;
JSONObject paths= json.getJSONObject("paths");
JSONObject summary = operation.getString("summary");
JSONObject tags = operation.getJSONObject("tags");
return tags + summary;
but it is not doing any thing. Can someone please guide me since I am new to java. Any help would be appreciated. Thanks in Advance
Solution 1:[1]
Well I guess you are using this Object and inside the defined class you have the function getJSONArray after that just use the new ArrayObject and pull the data what you need out of it.
Solution 2:[2]
In JSON values are present in [] are treated as arrays. So if you need to extract the tags, you will need to get them in a array like,
String json = "{\"tags\":[\"1\",\"2\",\"3\"]}";
JSONObject object = new JSONObject(json);
JSONArray array = object.getJSONArray("tags");
System.out.println(array);
P.S. I could not find the json posted in question to be valid, hence I have used some exmaple to explain the JSONArray.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Isandel |
| Solution 2 | pratap |
