0

i have a json string

 {
  "kind": "storage#objects",
  "items": [
    {
      "name" : "image.png",
      "id": "id_1",
      "mediaLink": "link",
      "contentType": "image/jpg"
    },
    {
      "name" : "image.png",
      "id": "id_1",
      "mediaLink": "link",
      "contentType": "image/jpg"
    }
  ]
}

I have a class in apex

public class JsonGCloudApiApex {
public class Item{
    public string name;
    public string id;
    public string mediaLink;
    public string contentType;  
}

public List<Item> items;

public static JsonGCloudApiApex parse(String json) {
    return (JsonGCloudApiApex) System.JSON.deserialize(json, JsonGCloudApiApex.class);
}}

i have in controller class

public List<JsonGCloudApiApex.Item> listItems {get; private set;}
...
objItems = parse(resp.getBody());
listItems = objItems.items;

This work very good, and i can see on logs the values are setting from model class. I need to create a apex:repeat for list variable: listItems (from controller variable name )

I try to use

<apex:repeat value="{!listItems}" var="item">
        <tr>
            <td class="withborder" style="width: 40%;">{!item.contentType}</td>
        </tr>
    </apex:repeat>

But i get the error message: Unknown property 'JsonGCloudApiApex.Item.contentType', on the model class the variable name (contentType) is declared and public How to create a list view on with apex:repeat to print key's values from list on controller?

1 Answer 1

3

You need to provide getters and setters to expose these properties to Visualforce:

public class JsonGCloudApiApex {
public class Item{
    public string name {get; set;}
    public string id {get; set;}
    public string mediaLink {get; set;}
    public string contentType  {get; set;}  
}
1
  • LOL i can't see on model class... thanks u David
    – pedroooo
    Sep 22, 2020 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .