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
om sai 10om sai 10 

called Rest Api when when i clicked on teh command button on the visual force page I got the following erro

om sai 10om sai 10
I called Rest Api when when i clicked on the command button on the visual force page I got the following error.

Malformed JSON: Expected '[' at the beginning of List/Set
Error is in expression '{!ApexNes}' in component <apex:commandButton> in page newsapipage: Class.System.JSON.deserialize: line 15, column 1
Class.ApexNewsApi.ApexNes: line 18, column 1
An unexpected error has occurred. Your solution provider has been notified. (System)



Apex Class:-

Public class ApexNewsApi
{
    public list<json2apex>j {get;set;} 
    
    public void ApexNes()
    {
        j=new list<json2apex>();
        
 Http http = new Http();
       HttpRequest request = new HttpRequest();
       request.setEndpoint('https://newsapi.org/v2/top-headlines?sources=cnn&apiKey=a257ba6c725a4b8dad4923aa24c75b0e');
       //request.setMethod('Get');
       request.setMethod('GET');
       request.setHeader('Content-Type', 'application/json;charset=UTF-8');
       HttpResponse response = http.send(request);
        system.debug('Response body has the following item'+response.getbody());
      
        j=(list<JSON2Apex>)json.deserialize(response.getBody(),list<JSON2Apex>.class);
    
        
    }
    
    public class JSON2Apex {

    public String status {get;set;} 
    public Integer totalResults {get;set;} 
    public List<Articles> articles {get;set;} 

    }
    
    public class Articles {
        public Source source {get;set;} 
        public Object author {get;set;} 
        public String title {get;set;} 
        public String description {get;set;} 
        public String url {get;set;} 
        public String urlToImage {get;set;} 
        public String publishedAt {get;set;} 
        public String content {get;set;} 
    }
        
    public class Source {
        public String id {get;set;} 
        public String name {get;set;} 
    }
        
}  

VF Page:-

<apex:page controller="ApexNewsApi">
    <apex:form>
        <apex:pageBlock>            
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Fetch" action="{!ApexNes}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
        <apex:pageblock>
            <apex:pageBlockSection>
                <apex:pageBlockTable value="{!j}" var="obj">
                
                <apex:column value="{!obj.status}" headerValue="Status"/>
                   
                    
                    
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>  


Json is:-

{"status":"ok","totalResults":10,"articles":[{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"WaPo: Manafort in plea deal talks - CNN Video","description":"The Washington Post is reporting that President Trump's former campaign chairman Paul Manafort is in talks with special counsel Robert Mueller about a possible plea just days before his second trial. CNN's Jessica Schneider reports.","url":"http://us.cnn.com/videos/politics/2018/09/12/manafort-mueller-washington-post-possible-plea-deal-schneider-lead-vpx.cnn","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/160815120149-01-paul-manafort-file-0815-super-tease.jpg","publishedAt":"2018-09-12T21:22:47.9539145Z","content":"Chat with us in Facebook Messenger. Find out what's happening in the world as it unfolds."},{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"Sign up for Hurricane Florence emails for the latest on the storm","description":null,"url":"https://mailchi.mp/cnn/florence","urlToImage":null,"publishedAt":"2018-09-12T21:07:05.1814584Z","content":null},{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"See Hurricane Florence from space - CNN Video","description":"The International Space Station shared views of Hurricane Florence as it moved closer to the US east coast.","url":"http://us.cnn.com/videos/weather/2018/09/10/hurricane-florence-from-space-orig-vstan-bdk.cnn","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/180912095605-florence-from-iss-0912-super-tease.jpg","publishedAt":"2018-09-12T19:38:07.6109632Z","content":"Chat with us in Facebook Messenger. Find out what's happening in the world as it unfolds."},{"source":{"id":"cnn","name":"CNN"},"author":"Andrea Diaz, CNN","title":"Trump did not incite violence against protesters at a 2016 campaign rally, court rules","description":"Three people who were pushed and shoved while protesting at a 2016 Donald Trump campaign rally cannot sue the President for inciting the crowd, a federal appeals court has ruled.","url":"http://us.cnn.com/2018/09/12/politics/trump-wins-dismissal-lawsuit-kentucky-trnd/index.html","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/180906215153-01-trump-rally-0906-super-tease.jpg","publishedAt":"2018-09-12T19:29:16Z","content":"(CNN) Three people who were pushed and shoved while protesting at a 2016 Donald Trump campaign rally cannot sue the President for inciting the crowd, a federal appeals court has ruled. The three-judge panel ruled unanimously Tuesday in favor of the President,… [+2752 chars]"},{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"LIVE: Waves crash onto Myrtle Beach shore - CNN","description":null,"url":"http://www.cnn.com/specials/live-video-1","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/170711161429-happening-now-16x9-artwork-super-tease.jpg","publishedAt":"2018-09-12T13:23:48.8050654Z","content":"Waves crash onto Myrtle Beach shore as the southeastern and mid-Atlantic US prepare for Hurricane Florence to make landfall."},{"source":{"id":"cnn","name":"CNN"},"author":"Julia Horowitz","title":"Jamie Dimon says he could beat Trump in an election, then retreats","description":"\"I should not have said it,\" Dimon later said.","url":"https://money.cnn.com/2018/09/12/news/companies/jamie-dimon-trump-jpmorgan/index.html","urlToImage":"https://i2.cdn.turner.com/money/dam/assets/170206092059-trump-jamie-dimon-banks-780x439.jpg","publishedAt":"2018-09-12T12:07:35Z","content":"\"I should not have said it,\" the JPMorgan Chase ( JPM ) CEO said in a statement. \"I'm not running for President. Proves I wouldn't make a good politician. I get frustrated because I want all sides to come together to help solve big problems.\" Earlier Wednesda… [+1627 chars]"},{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"Live updates: Hurricane Florence aims for the Carolinas - CNN","description":"Hurricane Florence is headed towards North and South Carolina. More than 1 million people face mandatory evacuation orders in the area. Follow here for the latest.","url":"http://us.cnn.com/us/live-news/hurricane-florence-dle/index.html","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/180911062749-hurricane-florence-approaches-super-tease.jpg","publishedAt":"2018-09-12T11:33:45Z","content":"President Trump just tweeted a Rose Garden video. Today’s message: Hurricane preparedness. “They say it’s about as big as they’ve seen,” he said of Hurricane Florence. “We’ll handle it. We’re ready, we’re able, we’ve got the finest people anywhere in the worl… [+453 chars]"},{"source":{"id":"cnn","name":"CNN"},"author":null,"title":"Hurricane Florence trajectory dips south  - CNN Video","description":"Hurricane models have shifted Florence to the south, threatening Charleston, SC and parts of Georgia.","url":"http://us.cnn.com/videos/weather/2018/09/12/hurricane-florence-weather-update-wednesday-september-12-vpx.cnn","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/180912052315-hurricane-florence-weather-update-wednesday-september-12-vpx-00005002-super-tease.jpg","publishedAt":"2018-09-12T09:37:50.9022994Z","content":"Chat with us in Facebook Messenger. Find out what's happening in the world as it unfolds."},{"source":{"id":"cnn","name":"CNN"},"author":"Faith Karimi and Steve Almasy, CNN","title":"Residents urged to flee 'monster' Hurricane Florence as it inches closer","description":"Hurricane Florence roared toward the Southeast coast early Wednesday as officials warned the more than 1 million people in its path to get out of the way or face its wrath.","url":"http://us.cnn.com/2018/09/12/us/hurricane-florence-south-east-coast-wxc/index.html","urlToImage":"https://cdn.cnn.com/cnnnext/dam/assets/180911133232-hurricane-florence-satellite-122-p-m-et-9-11-18-super-tease.jpg","publishedAt":"2018-09-12T06:12:19Z","content":"How are you preparing for Hurricane Florence? Text, iMessage or WhatsApp your videos, photos and stories to CNN: 347-322-0415 (CNN) Hurricane Florence roared toward the Southeast coast early Wednesday as officials warned the more than 1 million people in its … [+5321 chars]"},{"source":{"id":"cnn","name":"CNN"},"author":"Brian Stelter","title":"'60 Minutes' producer Jeff Fager leaving CBS amid allegations of inappropriate conduct","description":"CBS News president David Rhodes said that Fager's longtime No. 2, Bill Owens, will manage the \"60 Minutes\" team while a search is underway for Fager's replacement.","url":"http://money.cnn.com/2018/09/12/media/jeff-fager-cbs-steps-down/index.html","urlToImage":"https://i2.cdn.turner.com/money/dam/assets/180910120446-01-jeff-fager-file-780x439.jpg","publishedAt":"2018-09-12T01:42:22Z","content":"\"Jeff Fager is leaving the company effective immediately,\" CBS News president David Rhodes said in a memo to staffers on Wednesday. Rhodes said that Fager's longtime No. 2, Bill Owens, will manage the \"60 Minutes\" team while a search is underway \"for a new ex… [+558 chars]"}]}
    

Can somebody please help?

Thanks




    
    
    
    
    
    
Raj VakatiRaj Vakati




Looks like your code is fine .. Please go ahead add the remote site settings ... and print the dbeug to seee issue