You need to sign in to do that
Don't have an account?
Deepikareddy
After debugging , iam getting the value as: NULL...!
Can anyone have a solution to serialize it .. thank you ...!
Deserilize the dynamci jsondata and bind to wrapperclass
public class testingarryfuction { public StateInfodetails StateInfodetailswraper{get;set;} public string Stateidselected{get;set;} public boolean isSelected{get;set;} public testingarryfuction (){ string teststring ='{ "sucess":1,"data":{"Stateidselected":"2","StateInfodetails":{"stateName": "Andrapradesh","value": "apx" ,"rating":5},"isSelected":true}}'; Map<String, Object> maptest = (Map<String, Object>) JSON.deserializeUntyped(teststring); system.debug('mapped and deserialized data is::'+maptest); Object ob = (Object)maptest.get('data'); system.debug('get data is::'+ob); String srlze = System.JSON.serialize(ob); system.debug('again deserailized is ::'+srlze ); StateInfodetailswraper = (StateInfodetails)System.JSON.deserialize(srlze,StateInfodetails.class); system.debug('deserilize using the wrapperclass::::::'+StateInfodetailswraper ); system.debug(StateInfodetailswraper.stateName); } //this is a wrapper class public class StateInfodetails{ public string stateName{get;set;} public string value{get;set;} public integer rating{get;set;} } }
After debugging , iam getting the value as: NULL...!
Can anyone have a solution to serialize it .. thank you ...!
You have to access the "StateInfodetails" node.
Which means
String srlze = System.JSON.serialize(ob);
system.debug('again deserailized is ::'+srlze );
this would serealize the data node which has "Stateidselected" and "StateInfodetails" node.In order to parse the StateInfodetails instance you will have to access forst data then StateInfodetails:
Object ob = (Object)maptest.get('data');
system.debug('get data is::'+ob);
ob.get('StateInfodetails');
and then use it to serialize.
Cheers!!!