You need to sign in to do that
Don't have an account?
Rishav
Here is My Wrapper Class
controller class
VF Code to get Data
Please hlep me to show data from JSON into VF page.
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:
{ "mindTouchPage":{ "id":"1", "guid":"00000000000000000000000000000000", "draftstate":"inactive", "href":"https://steadfast-prod.mindtouch.us/@api/deki/pages/1?redirects=0", "deleted":"false", "datecreated":"Fri, 10 Jun 2016 20:30:17 GMT", "language":"en-US", "namespace":"main", "path":{ "seo":"true", "type1":"fixed", "text":"" }, "subpages":{ "mindTouchPage":[ { "id":"288", "guid":"a7afffb2634b453485bff59faed455f6", "draftstate":"inactive", "href":"https://steadfast-prod.mindtouch.us/@api/deki/pages/288?redirects=0", "deleted":"false", "datecreated":"Fri, 10 Jun 2016 21:33:04 GMT", "language":"en-US", "namespace":"main", "path":{ "seo":"true", "type1":"custom", "text":"The_MindTouch_Workbook/Chapter_I_-_Understand_users_&_groups/010_User_types_defined" }, "subpages":"", "title":"1. User types defined", "uriui":"https://steadfast-prod.mindtouch.us/?title=The_MindTouch_Workbook/Chapter_I_-_Understand_users_%26_groups/010_User_types_defined" }, { "id":"289", "guid":"88eae1c3ae25449eb27a518bfabf51ae", "draftstate":"inactive", "href":"https://steadfast-prod.mindtouch.us/@api/deki/pages/289?redirects=0", "deleted":"false", "datecreated":"Fri, 10 Jun 2016 21:33:09 GMT", "language":"en-US", "namespace":"main", "path":{ "seo":"true", "type1":"custom", "text":"The_MindTouch_Workbook/Chapter_I_-_Understand_users_&_groups/011_Create_groups" }, "subpages":"", "title":"2. Create groups", "uriui":"https://steadfast-prod.mindtouch.us/?title=The_MindTouch_Workbook/Chapter_I_-_Understand_users_%26_groups/011_Create_groups" }, { "id":"290", "guid":"e6da4dab743846f3bef6cd2826964937", "draftstate":"inactive", "href":"https://steadfast-prod.mindtouch.us/@api/deki/pages/290?redirects=0", "deleted":"false", "datecreated":"Fri, 10 Jun 2016 21:33:20 GMT", "language":"en-US", "namespace":"main", "path":{ "seo":"true", "type1":"custom", "text":"The_MindTouch_Workbook/Chapter_I_-_Understand_users_&_groups/012_Create_users" }, "subpages":"", "title":"3. Create users", "uriui":"https://steadfast-prod.mindtouch.us/?title=The_MindTouch_Workbook/Chapter_I_-_Understand_users_%26_groups/012_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 { get; set; } // 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(){ if(UserInfo.getUserType()=='Guest'){ return new pagereference ('/viptelaLoginController'); } else{ // status = 'User Authenticated'; // Call the webService Function // getDataFromMindTouch(); isUserAuthenticated = TRUE; getDataFromMindTouch(); 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); req.setHeader('Content-Type','application/json'); // Set Method,endpoint,and body req.setMethod('GET'); req.setEndpoint(mindTouchURL); try{ 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> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock>
Please hlep me to show data from JSON into VF page.
Controller Class > Line: 096 > you have to create the memory for the class, please include as follows - Added mindTouch = new JSON2Apex();
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
Thanks for your response.
I modified the class as u said.
Now also it's returning the null value only.