function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeepikareddyDeepikareddy 

Salesforce Json Deserialization Concept

public class testingarryfuction {

 
   public StateInfodetails StateInfodetailswraper{get;set;}
   
    public  testingarryfuction (){
    
    
     string teststring ='{ "sucess":1,"data":{"Stateidselected":"2","StateInfodetails":{"stateName": "Andrapradesh","value": "apx" ,"rating":5}}}';

    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;}
    
   }

   
   
   
  
}


Visualforce page:

 
<apex:page controller="testingarryfuction" >
   <apex:form >
     Name: <apex:inputText value="{!StateInfodetailswraper.stateName}" /> <br/><br/>
    
      Value: <apex:inputText value="{!StateInfodetailswraper.value}" /> <br/><br/>
      
       rating: <apex:inputText value="{!StateInfodetailswraper.rating}" /> <br/><br/>
       
       
    </apex:form>
    
</apex:page>

Result:
After deserilizing with the  StateInfodetails wrapperclass,iam gettng the values as null..! can anyone help me to resolve this solution. thanks you.. 
Deepali KulshresthaDeepali Kulshrestha
Hi Deepika,

I've gone through your code and inside your code you must do below changes:

1.Remove the "data " from inside the teststring and it will work fine:
(i.e.)
string teststring ='{ "sucess":1,{"Stateidselected":"2","StateInfodetails":{"stateName": "Andrapradesh","value": "apx" ,"rating":5}}};



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
DeepikareddyDeepikareddy
Hii.. deepali. thanks for ur reply,  but the thing is ,  jsonformat  is coming dynamically , i need to deserailze it .. 

Thanks and regards,
deepika