JSON标注的包装器类

时间:2019-01-29 10:04:22

标签: json salesforce apex

这是Json标注的包装器类,可以正常工作。

我需要从resdata列表中的media_type="image"的JSON中获取一个值。

//wrapperclass

public class MediaList_AC { 

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

    }   
}

//controller

    public class Adfclass_AC {
        public List<MediaList_AC> resdata {get;set;}
        public List<MediaList_AC> newdata {get;set;}
        public list<String> urlimage {get;set;}
        public String[] strings { 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 = (List<MediaList_AC>)Json.deserialize(result, List<MediaList_AC>.class);
            system.debug(urlimage);
        }
    }

0 个答案:

没有答案