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
rupesh ranjanrupesh ranjan 

System.JSONException: Unexpected character ('f' (code 102)):

Retrieving Email template from Json..
Getting an error System.JSONException: Unexpected character ('f' (code 102)):
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Controller////////////////////////////////////////////////////////
public class Calloutcontroller1 {
public List<template1> ConsoleWrapperList3{get;set;}
public List<template1> getperformcallout3(){
ConsoleWrapperList3 = new List<template1>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('http://webapi.demomail.net/test/bodyTemplate.js'); 
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
String replaceIllegal= res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('&quote;','').replaceAll('font;','');
ConsoleWrapperList3=(List<template1>)System.JSON.deserialize( res.getbody(),List<template1>.class);
}
return consolewrapperlist3;
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\VF Page\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<apex:page controller="Calloutcontroller1" sidebar="false" docType="html-5.0" >
<apex:form >
<apex:pageBlock id="ThePage">
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <messaging:htmlEmailBody >
 <html>
 <body>
                <span>Body</span>
                <div>
                    {!performcallout3}
                </div>
                 </body>
                 </html>
                </messaging:htmlEmailBody>
                <!--<apex:outputText value="" style="width:400px ; height:400px"></apex:outputText>-->
            </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Wrapper Class//////////////////////////////////////////////

public class template1{
public String Id{get;set;}
public String bodyT{get;set;}
}
 
Best Answer chosen by rupesh ranjan
suresh sanneboina 4suresh sanneboina 4
Hi,

change the vf page code as below
<apex:page controller="Calloutcontroller1" sidebar="false" docType="html-5.0" >

<apex:form >
<apex:pageBlock id="ThePage">
{!performcallout3}
</apex:pageBlock>
</apex:form>
</apex:page>

All Answers

suresh sanneboina 4suresh sanneboina 4
Hi,

Please use the below code.

This will solve your issue
public class Calloutcontroller1 {
    public List<template1> ConsoleWrapperList3{get;set;}
    public String response {get;set;}
    
    
    public List<template1> getperformcallout3(){
        ConsoleWrapperList3 = new List<template1>();
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setEndpoint('http://webapi.demomail.net/test/bodyTemplate.js'); 
        req.setMethod('GET');
        res = http.send(req);
        if(res.getstatusCode() == 200 && res.getbody() != null){
        System.debug(res.getbody());
        //String replaceIllegal= res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('&quote;','').replaceAll('font;','');
        String replaceIllegal=res.getbody().replaceAll('"','\'').replaceAll('[{]\'','{"').replaceAll('\'[:]\'','":"').replaceAll('\'[,]\'','","').replaceAll('\'[}]','"}');
        ConsoleWrapperList3=(List<template1>)System.JSON.deserialize(replaceIllegal,List<template1>.class);
        system.debug(ConsoleWrapperList3);
        }
        return consolewrapperlist3;
    }
    
    public class template1{
        public String Id{get;set;}
        public String bodyT{get;set;}
    }
}

 
rupesh ranjanrupesh ranjan
Yes error solved but nothing returned in this visual force page. its blank.
suresh sanneboina 4suresh sanneboina 4
Hi,

change the vf page code as below
<apex:page controller="Calloutcontroller1" sidebar="false" docType="html-5.0" >

<apex:form >
<apex:pageBlock id="ThePage">
{!performcallout3}
</apex:pageBlock>
</apex:form>
</apex:page>
This was selected as the best answer
rupesh ranjanrupesh ranjan
i know it works but Json contain HTML tag...
Json are displaying with HTML tag.. this sholud not be happen

I want without HTML tag
suresh sanneboina 4suresh sanneboina 4
Please use this code
<apex:page controller="Calloutcontroller1" sidebar="false" docType="html-5.0" >

<apex:form >
<apex:pageBlock id="ThePage">
<apex:outputText value="{!performcallout3[0].bodyT}" escape="false"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>
rupesh ranjanrupesh ranjan
Thanks @suresh. It works.. :)
 
rupesh ranjanrupesh ranjan
one more confusion....

How to get value from one Visual force tab to second Visual force tab???
suresh sanneboina 4suresh sanneboina 4
using key value pairs you can send the info
in the Apexclass create a method and in vf page create a button to call the method

PageReference pg=new Pagereference('/apex/test?id='+'value&name='+'name');
pg.setRedirect(true);
return pg;
 
rupesh ranjanrupesh ranjan
can u plz share me your gmail ID?
suresh sanneboina 4suresh sanneboina 4
ssanneboina@gmail.com