+ Start a Discussion

JSON data becoming Null After Deserialzation

Hi All,

I have one JSON Data , i am serializing that data, but it is becoming NULL after deserialization.
I want to access the value form JSON data into the VF page. 

Here is my JSON Data: 

      "datecreated":"Fri, 10 Jun 2016 20:30:17 GMT",
                                 "datecreated":"Fri, 10 Jun 2016 21:33:04 GMT",
                                 "title":"1. User types defined",
                                 "datecreated":"Fri, 10 Jun 2016 21:33:09 GMT",
                                 "title":"2.  Create groups",
                                 "datecreated":"Fri, 10 Jun 2016 21:33:20 GMT",
                                 "title":"3.  Create users",


Here is My Wrapper Class
public class JSON2Apex {
    public list<MindTouchPage> mindTouchData;
    public list<path> pathData;

	public class Path {
		public String seo;
		public String type1;
		public String text;

	public class MindTouchPage {
		public String id;
		public String guid;
		public String draftstate;
		public String href;
		public String deleted;
		public String datecreated;
		public String language;
		public String namespace;
		public Path path;
		public Subpages subpages;
		public String title;
		public String uriui;

	public class Subpages {
		public List<MindTouchPage> mindTouchPage;

	public static JSON2Apex parse(String json) {
		return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);

controller class
global with sharing class ViptelaCustLandingController {
   global static String responseData{get;set;}
   global static String status{get;set;}
   public boolean isUserAuthenticated{get;set;}
   Public Integer closeCaseCount{get;set;}
   public Integer openCaseCount{get;set;} 
   public JSON2Apex mindTouch{get;set;}
    public MindTouchDataWrapper wrapper {
    // Constructor
    public ViptelaCustLandingController(){
     // Get the count of closed Cases
     closeCaseCount = [SELECT COUNT() FROM CASE WHERE status = 'closed'];
     openCaseCount = [SELECT COUNT() FROM CASE WHERE status !='closed'];  
    // Code will invoke on pageLoad
    public pageReference redirectToCustomAuthPage(){
            return new pagereference ('/viptelaLoginController');
            // status = 'User Authenticated';
            // Call the webService Function
           // getDataFromMindTouch();
             isUserAuthenticated = TRUE;
             return null;

    // WebService Method to Call the "MindTouch" API
  //  @future(callout = true)
        public void getDataFromMindTouch(){
            status = 'method Called';
            System.debug('WebService Method Called');
            // MindTouch User Name
            String userName = '**********';
            String password = '***********';
            String mindTouchURL = 'https://***************';
            //  Prepare the HTTP request and response
            HttpRequest req = new HttpRequest();
            HttpResponse res = new HttpResponse();
            Http http = new Http();
            // Construct Authorization and Content Header
           // Blob headerValue = Blob.valueOf(userName+':'+password);
              Blob headerValue = Blob.valueOf(username + ':' + password);
              String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
           // String authorizationHeader = 'Basic'+ EncodingUtil.base64Encode(headerValue);
           // req.setHeader('Authorization', 'Basic UmlzaGF2OlJpc2hAMTk5MSo=');
            req.setHeader('Authorization', authorizationHeader);
            // Set Method,endpoint,and body
                res = http.send(req);
                System.debug('Response is =======' + res.getBody());
                //responseData = res.toString();
                responseData =res.getBody();
                status = 'TRUE';
                System.debug('response data variable value is' +responseData );
                //**************************Added by V******************************************
                //To overcome the limitation of @ variable in response, it is converted to the SFDC acceptable form using replace keywork
                //and same is reference in the MindTouchWrapper Class
                responseData = responseData.replace('"page"', '"mindTouchPage"');
                responseData = responseData.replace('"@id":', '"id":');
                responseData = responseData.replace('"@guid":', '"guid":');
                responseData = responseData.replace('"@draft.state":', '"draftstate":');
                responseData = responseData.replace('"@href":', '"href":');
                responseData = responseData.replace('"@deleted":', '"deleted":');
                responseData = responseData.replace('"date.created":', '"datecreated":');
                responseData = responseData.replace('"@seo":', '"seo":');
                responseData = responseData.replace('"@type":', '"type1":');
                responseData = responseData.replace('"#text":', '"text":');
                responseData = responseData.replace('"uri.ui":', '"uriui":');
                System.debug('response2 data variable value is' +responseData);
                //Parse is the deserialize method in the MindTouchWrapper class
               // MindTouchWrapper mindTouch = MindTouchWrapper.parse(responseData); 
                  mindTouch = JSON2Apex.parse(responseData);
                System.debug('Deserialized data is '+mindTouch);
                 //*************************Added by V*******************************************
            }Catch(System.CalloutException e){
                System.debug('ERROR' +e);
                System.debug('Response is ' + res.getBody());

VF Code to get Data
<apex:pageBlock >
                    <apex:pageBlockSection columns="2">
                         <apex:repeat value="{!mindTouch}" var="data">
                                  <apex:outputText value="{!data.id}"></apex:outputText>

Please hlep me to show data from JSON into VF page.
Srinivas SSrinivas S
Hi Rishav,

Controller Class > Line: 096 > you have to create the memory for the class, please include as follows -
//Parse is the deserialize method in the MindTouchWrapper class
// MindTouchWrapper mindTouch = MindTouchWrapper.parse(responseData); 
mindTouch = new JSON2Apex();
mindTouch = JSON2Apex.parse(responseData);
Added mindTouch = new JSON2Apex();

- Please mark as solution if your problem is resolved.
Hi Srinivasa,

Thanks for your response.
I modified the class as u said.
Now also it's returning the null value only.