+ Start a Discussion
Shavi DabgotraShavi Dabgotra 

How to get value from string?

Hi Everyone!
I am new to this. 
I have a string as:
String str = '{
         "@microsoft.graph.downloadUrl": "https://ww.google.com",
         "createdDateTime": "xyz"}';

I want to get the value of @microsoft.graph.downloadUrl and https://ww.google.com

I am using substringBetween but it is not working.
How to get these value and store in some variable.
I will be very grateful. 

Thank you in advance!

Daniel AhlDaniel Ahl
Hello Shavi!
The solution below should work.
String input = '[{"@microsoft.graph.downloadUrl": "https://ww.google.com","createdDateTime": "xyz"}]';
String finalString = '';
for(Object o : (List<Object>)JSON.deserializeUntyped(input)){
    Map<String, Object> objMap = (Map<String, Object>)o;
    finalString = (String)objMap.get('@microsoft.graph.downloadUrl');

System.debug(finalString); // https://ww.google.com

Hii Shavi!
Try The Following Code
String str =  '{"@microsoft.graph.downloadUrl": "https://www.google.com","createdDateTime": "xyz"}';
Map<string,object> lstAcc = (Map<string,object>) JSON.deserializeUntyped(str);
for(string s:lstAcc.keyset()){
    system.debug('s===> ' + s);
    system.debug('lstAcc ' + lstAcc.get(s));
Please Mark It As Best If It Helps
Thank You!