
I want to store key and value for the following json dynamically.
Please advise on this.Key as "01u9000000Ag0bbAAB" and value as "203"
String input = '[{"01u9000000Ag0bbAAB":"203","01u9000000Ag0bZAAR":"23","Id":"00k0w000003HeFhAAK"}]';
2 件の回答
Hi Udayar,Greetings to you!You need to use deserializeUntyped(jsonString) method that will deserialize the specified JSON string into collections of primitive data types. Please try below code:
I hope it helps you.Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.String input = '[{"01u9000000Ag0bbAAB":"203","01u9000000Ag0bZAAR":"23","Id":"00k0w000003HeFhAAK"}]';
List<Object> result = (List<Object>)JSON.deserializeUntyped(input);
for(Object obj : result) {
Map<String,Object> map1 = (Map<String,Object>)obj;
for(String key : map1.keyset()) {
System.debug('Key -->> ' + key);
System.debug('Value -->> ' + (String)map1.get(key));
}
}
Thanks and Regards,
Khan Anas