Hi/Dag Roelof, In a first approach I would not start by trying to map to actual domain objects (you can do that later), I would start by using NeoJSONObject, which is quite flexible and user friendly. Consider the following example: (NeoJSONObject fromString: '{ "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/wwx2vAS9DzFmmyeZefPjMtmCNOdjD80gvkXJcylloy40SiZOhdLHVdd..." }, "headerImage": { "guid": "29a2a516-f1d2-4713-9cbd-7a4458026057", "offsetPercentageX": 50, "offsetPercentageY": 50, "width": 1920, "height": 460, "url": "http://lh5.ggpht.com/SgH3Qo-vYI8GGm7-b-Qt6lXgsCAIoU2VDRwO5LYSBVNhhbZCetcvc88..." }, "productionPlaces": [] } ] }') artObjects first atPath: #(webImage url) First try to execute the expression inside the braces, and look at the result using the inspector. Unknown accessor automatically get translated to at: message sends (in this case, at: #artObjects). Using #atPath: you get the equivalent of webImage.url if you understand what I mean. To use NeoJSONObject in an actual API call, you could do ZnClient new contentReader: [ :entity | NeoJSONObject fromString: entity contents ]; url: '...'; get. Sven
On 5 Nov 2018, at 19:32, Roelof Wobben <r.wobben@home.nl> wrote:
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/wwx2vAS9DzFmmyeZefPjMtmCNOdjD80gvkXJcylloy40SiZOhdLHVdd..."
},
"headerImage": {
"guid": "29a2a516-f1d2-4713-9cbd-7a4458026057",
"offsetPercentageX": 50,
"offsetPercentageY": 50,
"width": 1920,
"height": 460,
"url": "http://lh5.ggpht.com/SgH3Qo-vYI8GGm7-b-Qt6lXgsCAIoU2VDRwO5LYSBVNhhbZCetcvc88..."
},
"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