I need to Show the Image in the Visualforce page based on the JSON property if Media type is equal to image.This is the Json Url:"https://wptestsmc.adflegal.org/wp-json/wp/v2/media?per_page=100 "

This is My controller class

public class Adfclass_AC {
    public List<MediaList_AC> resdata {get;set;}

    public Adfclass_AC() {
        Http h = new Http();
        HttpRequest req = new HttpRequest();

        // Send the request, and return a response
        HttpResponse res = h.send(req);
        String result = res.getBody();
        //resdata = MediaList_AC.parse(result);
        resData = (List<MediaList_AC>)Json.deserialize(result, List<MediaList_AC>.class);



This is the wrapper class

public class MediaList_AC { 
    public string id {get;set;}

    public string date_gmt {get;set;}
    public Cls_image_AC guid {get;set;}
    public class Cls_image_AC {
        public String rendered {get;set;}            
    public String media_type{get;set;}

closed as unclear what you're asking by Pranay Jaiswal, David Reed, glls, battery.cord, codeyinthecloud Dec 27 '18 at 15:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


You would need to make another wrapper for media_details.

if (resData.media_type == 'image')
   String imageURL = redData.media_details.file;

Pasting sample JSON into https://json2apex.herokuapp.com/ and letting it generate the code for you is often the simplest way to get a working parser. The generated code for your case is too big to post here. You can strip out parts of the generated code that you do not need.

Not the answer you're looking for? Browse other questions tagged or ask your own question.