1

JSON:

{parentComponentType=(
  {componentsList=( 
    {componentName=Class1, isSelected=True, lastModifiedByName=FirstName LastName, lastModifiedDate=}, 
    {componentName=Class2, isSelected=False, lastModifiedByName=FirstName LastName, lastModifiedDate=}
   ), 
   type=ApexClass
  }, 

  {componentsList=(
    { componentName=Page1, isSelected=True, lastModifiedByName=FirstName LastName, lastModifiedDate=}, 
    { componentName=Page2, isSelected=False, lastModifiedByName=FirstName LastName, lastModifiedDate=}
   ), 
   type=ApexPage
  }
)}

So far I did tried following :

public static void parse(String jsonStr){ 
  Map<String, Object> mapParent = (Map<String, Object>)JSON.deserializeUntyped(jsonStr); 

List<object> data2 = (List<Object>)data.get('parentComponentType');
System.debug('---*** dataMap2 :' + data2);
/* Debug I got :    
---***dataMap2 :({componentsList=({componentName=Class1, isSelected=True, lastModifiedByName=FirstName LastName, lastModifiedDate=}, 
{componentName=Class2, isSelected=False, lastModifiedByName=FirstName LastName, lastModifiedDate=}), type=ApexClass}, 
{componentsList=({componentName=Page1, isSelected=True, lastModifiedByName=FirstName LastName, lastModifiedDate=}, 
{componentName=Page2, isSelected=False, lastModifiedByName=FirstName LastName, lastModifiedDate=}), type=ApexPage})
*/
}
2

Below code should help you:

private map<string, string> parseJSONToMap(string JSONValue){
    JSONParser parser = JSON.createParser(JSONValue);
    map<string, string> jsonMap = new map<string, string>();
    string keyValue = '';
    string tempValue = '';
    while (parser.nextToken() != null) {
        if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
            keyValue = parser.getText();
            parser.nextToken();
            tempValue = parser.getText();
            jsonMap.put(keyValue, tempValue);            
        }
    }
    return jsonMap;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.