You need to sign in to do that
Don't have an account?

how to bind the values to the wrapper class in salesforce
public class jsontest { public loandetails loandetails{get;set;} public jsontest (){ string teststring ='{"status":1,"data":[{"$id":"1","type":"A","InterestAmount":"2.90","TotalAmount":"198000.00","year":2018,"Name":"Axis BANK"},{"$id":"2","type":"B","InterestAmount":"3.90","TotalAmount":"158000.00","year":2019,"Name":"ICICI BANK"},{"$id":"3","type":"A","InterestAmount":"2.90","TotalAmount":"258000.00","year":2018,"Name":"HDFC BANK"}]}'; Map<String, Object> mapobj= (Map<String, Object>)JSON.deserializeUntyped(teststring); system.debug('the Mapped and deserialized values are:'+ mapobj); list<Object> objj = (list<Object>)mapobj.get('data'); system.debug('the data value is :::'+objj); string SerilizeEmpdata = system.json.serialize(objj); system.debug('After Serilization:::'+ SerilizeEmpdata); loandetails =(loandetails)system.json.deserialize(SerilizeEmpdata,loandetails.class); system.debug(loandetails); system.debug('binded to loan information is:::'+loandetails.name); } //wrapperclass public class loandetails{ public string type{get;set;} public string InterestAmount{get;set;} public string TotalAmount{get;set;} public integer year{get;set;} public string name{get;set;} } }
Getting an error:
System.JSONException: Malformed JSON: Expected '{' at the beginning of object
Hello Deepikareddy,
you have to iterate through each object when you are serializing it as the class loan details doesn't accept the list of the JSON string.
Here is the code same as you have used i have just added for loop.
you can find the solution
if it worked for you please mark as solved
thanks
All Answers
Hello Deepikareddy,
you have to iterate through each object when you are serializing it as the class loan details doesn't accept the list of the JSON string.
Here is the code same as you have used i have just added for loop.
you can find the solution
if it worked for you please mark as solved
thanks
You can use this code this will help you.
Regards,
Soyab