You need to sign in to do that
Don't have an account?
kumar_arun
i want to get values from "Metadata" object in the json string. I easy get "FullName", "Size" but when I am parsing Metadata , it only return "{" in list<string> MetaData. How can i get "active":values in this list.
Thanks
How to get Object element in json?
JSON STRING: {"size":21,"totalSize":21,"done":true,"queryLocator":null,"entityTypeName":"ValidationRule","records":[{"attributes":{"type":"ValidationRule","url":"/services/data/v33.0/tooling/sobjects/ValidationRule/03d2800000083bXAAQ"},"Id":"03d2800000083bXAAQ","FullName":"SmartvCard__Note__c.SmartvCard__Not_new","CreatedDate":"2016-11-30T19:36:50.000+0000","TableEnumOrId":"01I280000022PApEAM","ValidationName":"Not_new","Metadata":{"description":null,"errorConditionFormula":"SmartvCard__Validation_Record__c = True","errorDisplayField":null,"errorMessage":"vCard Note record already exists. There can be only one vCard Note Record.","urls":null,"active":true}}]}
APEX: JSONParser parser = JSON.createParser(response.getBody()); List<String> fullName= new List<string>(); List<string> Tot_size=new list<string>(); List<string> metaData=new list<string>(); while (parser.nextToken() != null) { if( (parser.getCurrentToken() == JSONToken.FIELD_NAME) && ( parser.getText() == 'FullName') ){ parser.nextValue(); fullName.add(parser.getText()); } if( (parser.getCurrentToken() == JSONToken.FIELD_NAME) && ( parser.getText() == 'Size') ){ parser.nextValue(); Tot_size.add(parser.getText()); system.debug('====================='+ parser.nextValue()); } if( (parser.getCurrentToken() == JSONToken.FIELD_NAME) && ( parser.getText() == 'Metadata') ){ parser.nextValue(); metaData.add(parser.getText()); system.debug(metaData); } } }
i want to get values from "Metadata" object in the json string. I easy get "FullName", "Size" but when I am parsing Metadata , it only return "{" in list<string> MetaData. How can i get "active":values in this list.
Thanks
Try to use this approach. Create a Map of <String, Object> to store the "Metadata" attribute values and try with this code snippet: