0

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();
        req.setEndpoint('https://wptestsmc.adflegal.org/wp-json/wp/v2/media?per_page=100');
        req.setMethod('GET');

        // 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;}
}
1

You would need to make another wrapper for media_details.

if (resData.media_type == 'image')
   String imageURL = redData.media_details.file;
| improve this answer | |
1

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.

| improve this answer | |

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