+ Start a Discussion
Anil Bolisetty 2Anil Bolisetty 2 

Help regarding parsing json response

Hello,

could some one help me in parsing the below json,

{
"d": {
"results": [
{
"__metadata": {
"id": "https://testasugo.sharepoint.com/_api/Web/GetFolderByServerRelativePath(decodedurl='/Shared Documents/Salesforce/Salesforcetwo')",
"uri": "https://testasugo.sharepoint.com/_api/Web/GetFolderByServerRelativePath(decodedurl='/Shared%20Documents/Salesforce/Salesforcetwo')",
"type": "SP.Folder"
},
"Name": "Salesforcetwo"
},
{
"__metadata": {
"id": "https://testasugo.sharepoint.com/_api/Web/GetFolderByServerRelativePath(decodedurl='/Shared Documents/Salesforce/sub Salesforce')",
"uri": "https://testasugo.sharepoint.com/_api/Web/GetFolderByServerRelativePath(decodedurl='/Shared%20Documents/Salesforce/sub%20Salesforce')",
"type": "SP.Folder"
},
"Name": "sub Salesforce"
}
]
}
}


if i am using deserialization as i cannot use __metadata variable i am always getting null,could you help me in getting the value of __metadata in apex
MKRMKR
Hi,

Try parsing with Map instead.
 
public static void String parseJSON(String yourJSONInput) {
     Map<String, Object> topLevel = (Map<String, Object>)deserializeUntyped(yourJSONInput);
     Map<String, Object> d = (Map<String, Object>)topLevel.get('d');
     List<Object> results = (List<Object>)d.get('results');
     for(Object res : results) {
          Map<String, Object> resultObj = (Map<String, Object>)res;
          String metaD = resultObj.get('__metadata');
          //And so on...
     }
}

Regards,
MKR​​​​​​​