Hello,

I try to use the rijksmuseum api.
This gives json back for 10 paintings and the json looks like this :

{
  "elapsedMilliseconds": 164,
  "count": 359,
  "artObjects": [
    {
      "links": {
        "self": "https://www.rijksmuseum.nl/api/nl/collection/SK-C-5",
        "web": "https://www.rijksmuseum.nl/nl/collection/SK-C-5"
      },
      "id": "nl-SK-C-5",
      "objectNumber": "SK-C-5",
      "title": "Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de ‘Nachtwacht’",
      "hasImage": true,
      "principalOrFirstMaker": "Rembrandt Harmensz. van Rijn",
      "longTitle": "Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de ‘Nachtwacht’, Rembrandt Harmensz. van Rijn, 1642",
      "showImage": true,
      "permitDownload": true,
      "webImage": {
        "guid": "92253da1-794d-49f4-9e3c-e4c160715f53",
        "offsetPercentageX": 50,
        "offsetPercentageY": 100,
        "width": 2500,
        "height": 2034,
        "url": "http://lh6.ggpht.com/wwx2vAS9DzFmmyeZefPjMtmCNOdjD80gvkXJcylloy40SiZOhdLHVddEZLBHtymHu53TcvqJLYZfZF7M-uvoMmG_wSI=s0"
      },
      "headerImage": {
        "guid": "29a2a516-f1d2-4713-9cbd-7a4458026057",
        "offsetPercentageX": 50,
        "offsetPercentageY": 50,
        "width": 1920,
        "height": 460,
        "url": "http://lh5.ggpht.com/SgH3Qo-vYI8GGm7-b-Qt6lXgsCAIoU2VDRwO5LYSBVNhhbZCetcvc88ZPi518MTy0MHDrna4X4ZC1ymxVJVpzps8gqw=s0"
      },
      "productionPlaces": []
    },
    // more results...
  ]
}


Artobjects is the part that I want to use because that is the part that contains data from 10 paintings. 

I have tried to parse it like this :  

Painting class >> fromJSON: json [
| instance |
instance := self new.
instance
title: (json at: 'title');
painter: (json at: 'principalOrFirstMaker');
imageUrl: ((json at: 'webImage') at: 'url').
^ instance
]
and

PaintingCollection class >> fromJSON: json [
| instance artObjects |
instance := self new.
artObjects := json at: #artObjects.
artObjects
do: [ :eachArtObject | instance addPainting: (Painting fromJSON: eachArtObject) ].
^ instance
]

but that does not work.

Is there a better way to make this work.
and if so, can someone give me a example how to make this work.
This is my first project that I try to make after doing the MOOC course.

Regards,

Roelof

Reply via email to