0

I need to retrieve from a given JSON node only those attributes with particular value. In my case it is "Photorec" So for example...

                {

                    "Id": "a3TU0000008MMfwMAG",
                    "Measurement__c": "a3VU0000000huVaMAI",
                    "Available__c": false,
                    "Available_MT__c": "Photorec",
                    "Available_Ambient__c": false,
                    "Available_Ambient_MT__c": "Photorec",
                    "Available_Chilled__c": false,
                }

Here I would like to get back an array or list which has values "Available_MT__c" and "Available_Ambient_MT__c".

I am using Java's org.json.JSONObject in my code to represent this node.

Thanks in advance for any help.

1 Answer 1

1

Try something like this :)

            ArrayList<String> foundValues = new ArrayList<String>();
            ArrayList<String> jsonStringValues= new ArrayList<String>();
            jsonStringValues.add("Id");
            jsonStringValues.add("Available_Ambient_MT__c");
            jsonStringValues.add("Available_MT__c");
            jsonStringValues.add("Measurement__c");

            JSONObject jObj = yourItems.getJSONObject(i);
            for(String node: jsonStringValues){
               if(jObj.getString(node).equals("Photorec")){
                  foundValues.add(node);
               } 
            }
            System.out.println("Values found: " + foundValues);
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.